public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Paul.Domaskis <Paul.Domaskis@gmail.com>
To: cygwin@cygwin.com
Subject: Re: Direct/efficient way to chop off trailing \n
Date: Thu, 02 Oct 2014 18:20:00 -0000	[thread overview]
Message-ID: <loom.20141002T201957-325@post.gmane.org> (raw)
In-Reply-To: <6CF2FC1279D0844C9357664DC5A08BA20EC1B6C8@MLBXV06.nih.gov>

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

  reply	other threads:[~2014-10-02 18:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-01 21:52 Paul.Domaskis
2014-10-01 22:08 ` Gary Johnson
2014-10-01 22:50 ` Jim Garrison
2014-10-01 22:54   ` Keith Christian
2014-10-01 22:56     ` Keith Christian
2014-10-01 23:06   ` Gary Johnson
2014-10-01 23:11 ` Paul.Domaskis
2014-10-01 23:35   ` Andrey Repin
2014-10-02  2:25     ` Eliot Moss
2014-10-02  2:33       ` Eric Blake
2014-10-02 13:13         ` Buchbinder, Barry (NIH/NIAID) [E]
2014-10-02 18:20           ` Paul.Domaskis [this message]
2014-10-02 23:24             ` Keith Christian
2014-10-03  5:05             ` Andrey Repin
2014-10-03 13:25               ` Paul.Domaskis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20141002T201957-325@post.gmane.org \
    --to=paul.domaskis@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).