Skip to content

Commit

Permalink
Enable remote clipboard management.
Browse files Browse the repository at this point in the history
I'm using tmux for remote session. Using some great suggestions from
a few blog posts, we can expose our local clipboard to remote servers
so that we can easily yank text.

Inspiration:

- https://gist.github.com/gengmao/75e86c1d9d5427f9632d
- https://gist.github.com/burke/5960455
- https://seancoates.com/blogs/remote-pbcopy/
  • Loading branch information
issmirnov committed Jul 10, 2020
1 parent 708b179 commit e9da2a0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -7,3 +7,6 @@
[submodule "cheat/community"]
path = cheat/community
url = https://github.com/cheat/cheatsheets
[submodule "tmux/plugins/tmux-yank"]
path = tmux/plugins/tmux-yank
url = https://github.com/tmux-plugins/tmux-yank
15 changes: 15 additions & 0 deletions MacOS-LaunchAgents/README.md
@@ -0,0 +1,15 @@
# MacOS Launch Agents

Destination: `~/Library/LaunchAgents/`

## Remote Clipboard Managers

`pbcopy.plist` sets up a listener on localhost 2224.
Combined with an SSH directive `RemoteForward 2224 127.0.0.1:2224`,
this allows us to use `nc -q1 localhost 2224` on remote machines
to write to the MacOS clipboard.

See the tmux config setting `override_copy_command` for an example.

Note that you will need to launch this service with `launchctl load ~/Library/LaunchAgents/pbcopy.plist` first.

28 changes: 28 additions & 0 deletions MacOS-LaunchAgents/pbcopy.plist
@@ -0,0 +1,28 @@
<?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>

1 change: 1 addition & 0 deletions tmux/plugins/tmux-yank
Submodule tmux-yank added at 648005
6 changes: 6 additions & 0 deletions tmux/tmux.conf
Expand Up @@ -66,3 +66,9 @@ bind -n WheelUpPane if-shell -Ft= '#{?pane_in_mode,1,#{mouse_any_flag}}' \
bind -n WheelDownPane if-shell -Ft = '#{?pane_in_mode,1,#{mouse_any_flag}}' \
'send -Mt=' 'if-shell -Ft= "#{alternate_on}" \
"send -t= Down" "send -Mt="'

# enable yanking to remote clipboards.
# https://github.com/tmux-plugins/tmux-yank#controlling-yank-behavior
run-shell ~/.dotfiles/tmux/plugins/tmux-yank/yank.tmux
set -g @override_copy_command 'cat | head -c -1 | nc -q1 localhost 2224'
set -g @yank_with_mouse on # or 'on'

0 comments on commit e9da2a0

Please sign in to comment.