This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Direct/efficient way to chop off trailing \n


You're welcome, Paul.  But I see some streamlining that could be done
since I wrote that xx() alias long ago.  I do like Barry's "cygpath
-aw foo/bar | putclip -d" as it likely runs faster.

On Thu, Oct 2, 2014 at 12:20 PM, Paul.Domaskis <Paul.Domaskis@gmail.com> wrote:
> Keith Christian wrote:
>> This function echoes the present directory to the clipboard, so that
>> I don't have to enter the path manually.
>>
>> I use this function in a script that sources when a bash shell is
>> started.  Also echoes the path to the terminal for verification.
>> Handy for pasting directly into windows file dialogs.
>>
>> function xx() {
>>         DESCRIPTION="Copy the Windows drive/path/filename to the
> clipboard"
>>         cygpath -w "`pwd`"|tr -d "\012"|sed -e
>> 's/$/\\/'|putclip;echo;getclip;echo
>> }
>
> Thanks, Keith.  I think it will be educational for me just to figure
> this out.
>
> Andrey Repin wrote:
>> Most people either use Cygwin tools in isolation, or use Cygwin
>> tools from Windows tools.  The opposite is rare, and mostly boils
>> down to scripting, where you naturally use $(cygpath ...) to produce
>> desired results.
>
> Which I find odd. If you like bash, then that's going to be your
> explorer, and I am *never* able to work exclusively in cygwin.
>
> I suppose you can always use cygstart to launch app files
> or executables, but Windows can be very inconsistent at times.  I
> never know when cygstart will launch a new instance of an
> already-running app.  Also, I often encounter the need to specify a
> file location but not emulate a double-click on that file.
>
>>> So I can see why such a [\n chopping] switch has never been
>>> developed.  It's probably only needed for cygwin users, as it is
>>> the *unixy crowd that uses both Windows & *nix at the same time.
>>
>> The cygpath tool is Cygwin specific :) So there's no contradiction
>> to your words.
>
> Yeah, I suppose that was a circular truth.  I should have said that
> outside of cygwin, few people need to operate in both the POSIX and
> Windows world at the same time.  I guess those cases would be the ones
> in which cygpath is used, and those are also the cases in which it
> would be handy to have \n chopping capability built in to cygpath.
>
> Eliot Moss wrote:
>> You could write my solution as:
>>
>> echo -n `cygpath -aw foo`>/dev/clipboard
>>
>> though the ` (backtick) notation is deprecated these
>> days and $(...) is described as preferred.  But for many
>> little things like these I write bash functions (or
>> aliases, when they work, which they don't here).
>
> Yeah, it's from decades ago, when I started dabbling in unix.
>
>> The echo solution has the good property that echo is
>> a shell built-in and so does not require spawning
>> another process.  You had complained about speed, so
>> even though the echo approach does not seem to top
>> you list for elegance, it might for performance
>
> Eric Blake wrote:
>> The same is true of printf.
>
> I don't care about the computational speed, I probably won't notice
> any difference.  I care about reducing it to the simplest sequence of
> actions for the user, not only in terms of keystrokes, but also the
> cognitive simplicity of the code (which is pretty subjective, I know).
> I will give you code idiom a try.  Thanks.
>
> Eric Blake wrote:
>> 'echo -n' is not portable (in fact, you can disable it in bash, and
>> it may misbehave if cygpath outputs a leading - or contains any \);
>> it's better to use 'printf' for that purpose:
>>
>> printf %s `cygpath -aw foo`>/dev/clipboard
>
> A new bash command of which I was not aware.  Thanks!
>
> Buchbinder, Barry wrote:
>> Converting \n line endings to \r\n might work for you when you paste
>> into a Windows app.  It does for me.
>>
>> cygpath -aw foo/bar | putclip -d
>
> This is awesome!  Even better than
>
>    cygpath -aw foo/bar | unix2dos > /dev/clipboard
>
> Thanks a million!!!
>
>
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]