3 ms·
I want "remote pbcopy"! I'd like to be able to log in to any remote host (usually Linux in my case), then tack something onto the command line I'm typing to cop
by hibbelig 12y ago
I want "remote pbcopy"! I'd like to be able to log in to any remote host (usually Linux in my case), then tack something onto the command line I'm typing to copy it into the pastebuffer.
ssh somehost
cd /some/dir
grep -lr foo . | remote_pbcopy
I guess something like this is possible with GNU Screen or with Tmux, and perhaps the Tmux/iTerm interaction helps, but I've never figured it out.
- pikachu_is_cool 12y agoOn your Mac: ssh -R 19999:localhost:22 remote_host On the remote host: command_that_prints_stuff | ssh localhost -p 19999 pbcopy ________ The first command routes the port 19999 on the remote host to port 22 on the computer you're using. ssh part on the second command connects to 19999 (and thus 22 on your computer) and runs the pbcopy command in the current shell (which is the pipe from command_that_prints_stuff)
- hibbelig 12y agoThat's cool. Thanks!
- rasur 12y agoYou could probably squash the 'ssh localhost -p 19999 pbcopy' into an alias too, to reduce the typing further. EDIT: oh wait.. remote host.. ok, maybe, maybe not. depends on your environments I guess.
- enneff 12y agoWhy not just ssh remote_host command_that_prints_stuff | pbcopy ?
- pikachu_is_cool 12y agoDepends on the situation, if you want to run a quick script then yours would be better. If you're spending a lot of time in remote_host then mine might make more sense.
- cobbal 12y agoI usually try to stick it all on one line when I have to do that, something like ssh somehost 'cd /some/dir; grep -lr foo .' | pbcopy not very flexible, but it works for many cases
- datr 12y agoI don't know if there's an equivalent for OSX but if you're running linux you can use x11 forwarding to do this: ssh -x example.com cat /var/log/syslog | grep event | xclip -i Your X clipboard will be shared with the host so the output will be placed into your local clipboard.