From 760542b2862a63c29823602be3af59dfcc718995 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Tue, 8 Apr 2025 11:21:55 +0100 Subject: [PATCH] tmux: add copy/paste hooks --- tmux.conf | 8 +++++++- tmux.linux.conf | 14 ++++++++++++++ tmux.mac.conf | 9 +++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tmux.linux.conf create mode 100644 tmux.mac.conf diff --git a/tmux.conf b/tmux.conf index befd332..afc326d 100644 --- a/tmux.conf +++ b/tmux.conf @@ -98,6 +98,12 @@ set -g @plugin 'seebi/tmux-colors-solarized' set -g @resurrect-strategy-vim 'session' set -g @continuum-restore 'on' +# Load OS-specific settings +if-shell "uname | grep -q Linux" "source-file ~/.tmux.linux.conf" +if-shell "uname | grep -q Darwin" "source-file ~/.tmux.mac.conf" + +# Load any system-specific/private settings +if-shell "[ -f ~/.tmux.private]" "source ~/.tmux.private" + # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) run -b '~/.tmux/plugins/tpm/tpm' - diff --git a/tmux.linux.conf b/tmux.linux.conf new file mode 100644 index 0000000..8d3c5c7 --- /dev/null +++ b/tmux.linux.conf @@ -0,0 +1,14 @@ +# Detect the display server protocol and set clipboard commands​ +if-shell '[ "$XDG_SESSION_TYPE" = "wayland" ]' \ + 'set -g copy-command "wl-copy"; set -g paste-command "wl-paste -n"' \ + 'set -g copy-command "xclip -sel clip -i"; set -g paste-command "xclip -sel clip -o"' + +# Take the buffer and send it to the system clipboard +bind C-c run "tmux save-buffer - | $copy_command" + +# y in copy mode takes selection and sends it to system clipboard +bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "$copy_command" + +# And the reverse - Prefix Ctrl-v fills tmux buffer from system clipboard, then +# pastes from buffer into tmux window +bind C-v run-shell '$paste_command | tmux load-buffer - \; paste-buffer' \ No newline at end of file diff --git a/tmux.mac.conf b/tmux.mac.conf new file mode 100644 index 0000000..09bbb61 --- /dev/null +++ b/tmux.mac.conf @@ -0,0 +1,9 @@ +# Prefix Ctrl-C takes what's in the buffer and sends it to system clipboard via pbcopy +bind C-c run "tmux save-buffer - | pbcopy" + +# y in copy mode takes selection and sends it to system clipboard via pbcopy +bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy" + +# Prefix Ctrl-v fills tmux buffer from system clipboard via pbpaste, then +# pastes from buffer into tmux window +bind C-v run "tmux set-buffer \" $(pbpaste)\"; tmux paste-buffer" \ No newline at end of file