Skip to content

Instantly share code, notes, and snippets.

@huangyg11
Forked from burke/remotepaste.md
Last active January 16, 2017 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huangyg11/61f8a67c4d326e661197ae6c28252ce8 to your computer and use it in GitHub Desktop.
Save huangyg11/61f8a67c4d326e661197ae6c28252ce8 to your computer and use it in GitHub Desktop.
This fork sets up keybindings in tmux that allow you to copy to your OS X clipboard from tmux running inside an SSH connection to a remote host. In tmux copy mode, hit enter to copy.

Local (OS X) Side

~/Library/LaunchAgents/pbcopy.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
     <key>Label</key>
     <string>localhost.pbcopy</string>
     <key>ProgramArguments</key>
     <array>
         <string>/usr/bin/pbcopy</string>
     </array>
    <key>EnvironmentVariables</key>
    <dict>
        <key>LANG</key>
        <string>zh_CN.UTF-8</string>
    </dict>
     <key>inetdCompatibility</key>
     <dict>
          <key>Wait</key>
          <false/>
     </dict>
     <key>Sockets</key>
     <dict>
          <key>Listeners</key>
               <dict>
                    <key>SockServiceName</key>
                    <string>2224</string>
                    <key>SockNodeName</key>
                    <string>127.0.0.1</string>
               </dict>
     </dict>
</dict>
</plist>

~/.ssh/config

Host myhost
    HostName 192.168.1.123
    User myname
    RemoteForward 2224 127.0.0.1:2224

After adding the PLists above, you'll have to run:

launchctl load ~/Library/LaunchAgents/pbcopy.plist

Remote (Linux) Side

~/.tmux.conf

set-window-option -g mode-keys vi
bind-key -tvi-copy Enter copy-pipe "nc -q1 localhost 2224"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment