Getclip and putclip
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">
- !/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>
Another example, is running a diff over two clipboard items you've copied to the clipboard. <geshi lang="bash"> getclip > /tmp/a getclip > /tmp/b vi <(diff <(sed 's/></>\n</g' /tmp/a) <(sed 's/></>\n</g' /tmp/b) ) </geshi>
Note, on the Mac you can do the same thing with pbcopy and pbpaste