Thursday, September 16, 2010

Linking a remote command line and the clipboard

Being logged in to a server via ssh and iTerm, I sometimes want to get the result of a remote command to the local clipboard. The commands pbcopy and pbpaste do this for the local machine, but don't work remotely. However, it's possible to ssh back to you machine (if no firewalls interfere) and invoke these commands:
alias pbcopy "ssh `echo $SSH_CLIENT | cut -f 1 -d ' '` pbcopy"
alias pbpaste "ssh `echo $SSH_CLIENT | cut -f 1 -d ' '` pbpaste"
Of course this is only convenient if you have ssh key authentication set up.