Getclip and putclip

From EggeWiki
Revision as of 23:38, 8 October 2009 by Brianegge (talk | contribs) (Created page with ''''getclip''' and '''putclip''' are two tools used by power Cygwin users. For years I went about not knowing about these two very useful commands. Quite simply, they either cop…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

getclip and putclip are two tools used by power Cygwin users. For years I went about not knowing about these two very useful commands. Quite simply, they either copy the clipboard to standard out or copy stdin to the clipboard. For example, to copy a file onto the clipboard:

<geshi lang="bash"> putclip < /etc/hosts </geshi>

Or to write the clipboard to a file: <geshi lang="bash"> getclip > myfile.txt </geshi>

Another useful feature I've found is writing small scripts to transform whatever is on the clipboard. For example, I needed to copy column data from one application, and paste it into my Eclipse IDE. I would copy the data, run the following script, and then paste.

<geshi lang="bash">

  1. !/bin/bash

tmp=/tmp/$(basename $0).$$ lines=$(getclip | wc -l) if [ "$1" == "--quote" ]; then

 getclip | ruby -ne 'i = $_.strip; print "\"#{i}\", "' > $tmp

else

 getclip | ruby -ne 'i = $_.strip; print (if i =~ /^$/ then "" elsif i =~ /^\d+[.]0+$/ then "#{i.to_i.to_s}, " elsif i =~ /[A-Za-z]/ then "\"#{i}\", " else "#{i}, " end)' > $tmp

fi putclip < $tmp /bin/rm $tmp echo "Transformed $lines items" </geshi>

Note, on the Mac you can do the same thing with pbcopy and pbpaste