delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/10/02/14:20:45

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:to:from:subject:date:message-id:references
:mime-version:content-type:content-transfer-encoding; q=dns; s=
default; b=C8CSOELZj101ElDz4heGfNheuPFXIvzpIJZBzKT46zPEZ0cZdX7wH
WvBedWsp1eTv5b3CJyYp3pVt1TZXlciKNA8yy85vG2+gbV6xmpIB7Ux5eVrHtjdj
coVuMj+LgUovRrxvwyYe8g9E7Ns1eiwqH1UufUvXLWmgdl98toud3M=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:to:from:subject:date:message-id:references
:mime-version:content-type:content-transfer-encoding; s=default;
bh=eVO/mw6Q21UlY68Tsh4cYU/9ZsU=; b=KgPs2khZMJhim6mqiXnjBH1Y9L2f
4VvPUWV9biUJe8oY4eypHjZGmylxh66RfE/JjWml7o+ApaaEHsrhjR/ilMJmy6TX
eDQ76FnHdNxFR1IXtoruj+kLyHGeAyIgmBFmyfbb/PBRabZ3NPygM05NA+lIauue
4073ezJLZbnBUx4=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2
X-HELO: plane.gmane.org
To: cygwin AT cygwin DOT com
From: "Paul.Domaskis" <Paul DOT Domaskis AT gmail DOT com>
Subject: Re: Direct/efficient way to chop off trailing \n
Date: Thu, 2 Oct 2014 18:20:07 +0000 (UTC)
Lines: 93
Message-ID: <loom.20141002T201957-325@post.gmane.org>
References: <loom DOT 20141001T235147-60 AT post DOT gmane DOT org> <loom DOT 20141002T011040-272 AT post DOT gmane DOT org> <1576090815 DOT 20141002032152 AT yandex DOT ru> <542CB798 DOT 8000800 AT cs DOT umass DOT edu> <542CB963 DOT 4010004 AT redhat DOT com> <6CF2FC1279D0844C9357664DC5A08BA20EC1B6C8 AT MLBXV06 DOT nih DOT gov>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019