Re: Direct/efficient way to chop off trailing \n
Andrey Repin yandex.ru> writes: > I like bash, but it's no damned explorer, and can't be the one. > Simple for lack of visualization. My regular "shell" is > http://farmanager.com/ I would have said that bash is not a damned explorer -- rather, it's a darn good shell, which can often times be much better than an explorer. pushd +3. vim'ing on the command line. fc. NewCommand !!:$ diff -qr Long/Path/1 Another/Long/Path/From/Dir 2>&1 | tee ~/tmp/diff.out tar cf - Some/Directory | ( cd Other/Long/Path ; tar xf - ) find ... | xargs , etc., etc. How can *any* non-command-line compete. It would be like having one's hands chopped off. As for Far Manger, unfortunately, my environment is locked down. It took a very long time to get cygwin, and an old snapshot at that. >> 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. > > That's not even Windows - that's a per-application behavior. Yes, but even in the Office suite, I've been surprised in the past. It is not trustable. -- 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
Re: Direct/efficient way to chop off trailing \n
Greetings, Paul.Domaskis! > 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, I like bash, but it's no damned explorer, and can't be the one. Simple for lack of visualization. My regular "shell" is http://farmanager.com/ > 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. That's not even Windows - that's a per-application behavior. > Also, I often encounter the need to specify a > file location but not emulate a double-click on that file. I get it by simple copying the file location from panel. Really, try it. You might end liking it beyond explanation :) -- WBR, Andrey Repin (anrdae...@yandex.ru) 03.10.2014, <8:55> Sorry for my terrible english... -- 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
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 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
Re: Direct/efficient way to chop off trailing \n
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
RE: Direct/efficient way to chop off trailing \n
Eric Blake sent the following at Wednesday, October 01, 2014 10:33 PM >On 10/01/2014 08:25 PM, Eliot Moss wrote: > >> You could write my solution as: >> >> echo -n `cygpath -aw foo`>/dev/clipboard > >'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 > >> The echo solution has the good property that echo is >> a shell built-in and so does not require spawning >> another process. > >The same is true of printf. 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 - Barry Disclaimer: Statements made herein are not made on behalf of NIAID.
Re: Direct/efficient way to chop off trailing \n
On 10/01/2014 08:25 PM, Eliot Moss wrote: > You could write my solution as: > > echo -n `cygpath -aw foo`>/dev/clipboard '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 > The echo solution has the good property that echo is > a shell built-in and so does not require spawning > another process. The same is true of printf. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: Direct/efficient way to chop off trailing \n
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). 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 :-) ... Best -- Eliot -- 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
Re: Direct/efficient way to chop off trailing \n
Greetings, Paul.Domaskis! > Jim, I think you're right. cygpath could benefit a lot from a -n > switch to suppress the new line. From google, however, it's actually > just li'l olde me that would benefit as no one else seems to have the > want for it. That's just happened to be opposite case of common usage, I suppose. 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. > So I can see why such a 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. -- WBR, Andrey Repin (anrdae...@yandex.ru) 02.10.2014, <3:17> Sorry for my terrible english... -- 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
Re: Direct/efficient way to chop off trailing \n
On 2014-10-01, Paul.Domaskis wrote: > cygpath -aw foo | tr -d '\n' > /dev/clipboard Gary Johnson wrote: > Define a function in your ~/.bashrc. > > winclip() > { > cygpath -aw "$ " | tr -d '\n' > /dev/clipboard > } > > Then just execute > > winclip TheFile Jim Garrison wrote: > Sounds like cygpath needs a "-n" option which eliminates the > trailing newline. Eliot Moss wrote: > echo -n $(cygpath -aw foo) > /dev/clipboard? Gary, I was hoping for a magic bullet code idiom so that I don't have to haul around a growing .alias.bash file. But I think your solution might be the only one that significantly cuts down on the typing. Jim, I think you're right. cygpath could benefit a lot from a -n switch to suppress the new line. From google, however, it's actually just li'l olde me that would benefit as no one else seems to have the want for it. So I can see why such a 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. Eliot, your solution takes 2 characters less than mine. If I want to live without spaces aroud the "$(" and the ")". Which I suppose I could do, for 2 characters. I'm a bit enamoured of the linear simplicity of my original pipeline, though. Appreciate the other perspective, though. Thank you all. -- 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
Re: Direct/efficient way to chop off trailing \n
On 2014-10-01, Jim Garrison wrote: > On 10/1/2014 2:52 PM, Paul.Domaskis wrote: > > Running bash in a Windows environment, I often find the need to > > generate a full Windows path to a file so that I can access the file > > from a Windows app. > [snip] > >... but it does remove the trailing \n which chokes up > > Windows. > > Sounds like cygpath needs a "-n" option which eliminates the > trailing newline. The trouble with that is that the "problem" is common to (almost?) all Unix commands, not just cygpath. That is, they all send their output to stdout as lines of text, each line terminated by a newline, as it should be. You can send the output of any command to /dev/clipboard and it will be terminated by a newline. If that's not desired, then one needs to take extra steps in the pipeline, which is what tr is for. Another solution would be to wrap the redirection to /dev/clipboard in a function or script that takes your "-n" option and pipe the output of cygpath or whatever command to that wrapper. Regards, Gary -- 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
Re: Direct/efficient way to chop off trailing \n
Looks like the cygpath line was broken in two, and the closing brace isn't visibile when reading in Gmail. Readers take note of that. On Wed, Oct 1, 2014 at 4:54 PM, 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 > } > > On Wed, Oct 1, 2014 at 4:50 PM, Jim Garrison wrote: >> On 10/1/2014 2:52 PM, Paul.Domaskis wrote: >>> Running bash in a Windows environment, I often find the need to >>> generate a full Windows path to a file so that I can access the file >>> from a Windows app. >> [snip] >>>... but it does remove the trailing \n which chokes up >>> Windows. >> >> Sounds like cygpath needs a "-n" option which eliminates the >> trailing newline. >> >> >> -- >> Jim Garrison (j...@acm.org) >> PGP Keys at http://www.jhmg.net RSA 0x04B73B7F DH 0x70738D88 >> >> -- >> 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
Re: Direct/efficient way to chop off trailing \n
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 } On Wed, Oct 1, 2014 at 4:50 PM, Jim Garrison wrote: > On 10/1/2014 2:52 PM, Paul.Domaskis wrote: >> Running bash in a Windows environment, I often find the need to >> generate a full Windows path to a file so that I can access the file >> from a Windows app. > [snip] >>... but it does remove the trailing \n which chokes up >> Windows. > > Sounds like cygpath needs a "-n" option which eliminates the > trailing newline. > > > -- > Jim Garrison (j...@acm.org) > PGP Keys at http://www.jhmg.net RSA 0x04B73B7F DH 0x70738D88 > > -- > 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
Re: Direct/efficient way to chop off trailing \n
On 10/1/2014 2:52 PM, Paul.Domaskis wrote: > Running bash in a Windows environment, I often find the need to > generate a full Windows path to a file so that I can access the file > from a Windows app. [snip] >... but it does remove the trailing \n which chokes up > Windows. Sounds like cygpath needs a "-n" option which eliminates the trailing newline. -- Jim Garrison (j...@acm.org) PGP Keys at http://www.jhmg.net RSA 0x04B73B7F DH 0x70738D88 -- 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
Re: Direct/efficient way to chop off trailing \n
On 2014-10-01, Paul.Domaskis wrote: > Running bash in a Windows environment, I often find the need to > generate a full Windows path to a file so that I can access the file > from a Windows app. > > If I use > >cygpath -aw TheFile > /dev/clipboard > > I can paste into the Windows file-opener without browsing. Also, I > don't need to mouse around to highlight the result of cygpath. > However, the clipboard always contains an invisible carriage return, > which I have to remove by pressing backspacing. This doesn't visibly > change anything, but it does remove the trailing \n which chokes up > Windows. > > Since I hate manually deleting stuff that I can't see, the most > efficient way around this seems to be: > >cygpath -aw | tr -d '\n' > /dev/clipboard > > This is starting to get longer and longer. It is comprising the whole > goal of getting a sequence of operations that is so brief that one > does not sigh at having to do it countless times. > > Is there a more succinct way to get a clean path for a file from the > bash shell into the Windows clipboard? Define a function in your ~/.bashrc. winclip() { cygpath -aw "$@" | tr -d '\n' > /dev/clipboard } Then just execute winclip TheFile Regards, Gary -- 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