Forked from: https://gist.github.com/gengmao/75e86c1d9d5427f9632d Original Author: @gengmao Minor changes by @issmirnov, specifically update config for modern tmux and add some notes.
I like to use mouse mode in tmux to scroll text in windows/panes, however I found there is problem when I wanna select and copy text into local system clipboard.
The problem is described at https://awhan.wordpress.com/2012/04/18/tmux-copy-paste-with-mouse/. The workaround is zoom tmux pane -> turn off mouse mode -> select with Option key and copy, then go back. But it is not ideal.
Fortunately I found http://seancoates.com/blogs/remote-pbcopy and https://gist.github.com/burke/5960455. I tweak them a bit and got what I want - select text in one pane in mouse mode correctly and copy it back to Mac system clipboard.
Here are my configurations:
<?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>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>
RemoteForward 2224 127.0.0.1:2224
After adding the plist above, you'll have to run:
launchctl load ~/Library/LaunchAgents/pbcopy.plist
# enable mouse. you can use mouse scroll window/pane and select text, but you can't copy text without the copy-pipe setting below.
set -g mode-mouse on
setw -g mouse-select-window on
setw -g mouse-select-pane on
# click mouse and select the text in tmux window/pane, and hit 'y' key to copy it back though a local port opened by ssh.
# - don't release mouse before hit 'y' key.
bind-key -T copy-mode-vi 'y' copy-pipe "cat | nc -q1 localhost 2224"
I found the pbpaste.plist is unnecessary. In mouse mode, you can paste contents from mac system clipboard into remote tmux session freely (maybe because I am using iTerm2)