From e9da2a0f2039a5be6eb4190391faa1f1a13a2d9f Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Fri, 10 Jul 2020 13:11:35 -0700 Subject: [PATCH] Enable remote clipboard management. 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/ --- .gitmodules | 3 +++ MacOS-LaunchAgents/README.md | 15 +++++++++++++++ MacOS-LaunchAgents/pbcopy.plist | 28 ++++++++++++++++++++++++++++ tmux/plugins/tmux-yank | 1 + tmux/tmux.conf | 6 ++++++ 5 files changed, 53 insertions(+) create mode 100644 MacOS-LaunchAgents/README.md create mode 100644 MacOS-LaunchAgents/pbcopy.plist create mode 160000 tmux/plugins/tmux-yank diff --git a/.gitmodules b/.gitmodules index 17aff72c..fef86191 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/MacOS-LaunchAgents/README.md b/MacOS-LaunchAgents/README.md new file mode 100644 index 00000000..d84eb7b3 --- /dev/null +++ b/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. + diff --git a/MacOS-LaunchAgents/pbcopy.plist b/MacOS-LaunchAgents/pbcopy.plist new file mode 100644 index 00000000..e0d6006a --- /dev/null +++ b/MacOS-LaunchAgents/pbcopy.plist @@ -0,0 +1,28 @@ + + + + + Label + localhost.pbcopy + ProgramArguments + + /usr/bin/pbcopy + + inetdCompatibility + + Wait + + + Sockets + + Listeners + + SockServiceName + 2224 + SockNodeName + 127.0.0.1 + + + + + diff --git a/tmux/plugins/tmux-yank b/tmux/plugins/tmux-yank new file mode 160000 index 00000000..648005db --- /dev/null +++ b/tmux/plugins/tmux-yank @@ -0,0 +1 @@ +Subproject commit 648005db64d9bf3c4650eff694ecb6cf3e42b0c8 diff --git a/tmux/tmux.conf b/tmux/tmux.conf index 99835cf0..35ad70ae 100644 --- a/tmux/tmux.conf +++ b/tmux/tmux.conf @@ -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'