From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12443 invoked by alias); 2 Oct 2014 23:24:11 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 12424 invoked by uid 89); 2 Oct 2014 23:24:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ig0-f177.google.com Received: from mail-ig0-f177.google.com (HELO mail-ig0-f177.google.com) (209.85.213.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 02 Oct 2014 23:24:06 +0000 Received: by mail-ig0-f177.google.com with SMTP id a13so369924igq.10 for ; Thu, 02 Oct 2014 16:24:03 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.42.206.210 with SMTP id fv18mr8980985icb.47.1412292243448; Thu, 02 Oct 2014 16:24:03 -0700 (PDT) Received: by 10.50.191.132 with HTTP; Thu, 2 Oct 2014 16:24:03 -0700 (PDT) In-Reply-To: References: <1576090815.20141002032152@yandex.ru> <542CB798.8000800@cs.umass.edu> <542CB963.4010004@redhat.com> <6CF2FC1279D0844C9357664DC5A08BA20EC1B6C8@MLBXV06.nih.gov> Date: Thu, 02 Oct 2014 23:24:00 -0000 Message-ID: Subject: Re: Direct/efficient way to chop off trailing \n From: Keith Christian To: cygwin@cygwin.com Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2014-10/txt/msg00027.txt.bz2 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