diff options
-rw-r--r-- | tmux/.config/tmux/ssh.conf | 1 | ||||
-rw-r--r-- | tmux/.config/tmux/tmux.conf | 1 | ||||
-rwxr-xr-x | tmux/.local/bin/tmux-clipboard.sh | 57 |
3 files changed, 59 insertions, 0 deletions
diff --git a/tmux/.config/tmux/ssh.conf b/tmux/.config/tmux/ssh.conf index b5a5054..15f1c97 100644 --- a/tmux/.config/tmux/ssh.conf +++ b/tmux/.config/tmux/ssh.conf @@ -3,6 +3,7 @@ set-option -g remain-on-exit on set-option -g prefix C-b set-option -g status off +set-option -g set-clipboard on set-hook -g pane-died "detach -E 'tmux -L ssh kill-pane; tmux attach'" diff --git a/tmux/.config/tmux/tmux.conf b/tmux/.config/tmux/tmux.conf index 28fa23c..0a7b5c6 100644 --- a/tmux/.config/tmux/tmux.conf +++ b/tmux/.config/tmux/tmux.conf @@ -45,6 +45,7 @@ if "test ! -d $XDG_CONFIG_HOME/tmux/plugins/tpm" \ && $XDG_CONFIG_HOME/tmux/plugins/tpm/bin/install_plugins'" run '$XDG_CONFIG_HOME/tmux/plugins/tpm/tpm' +run '~/.local/bin/tmux-clipboard.sh' set-hook -g session-created 'if -F "#{m/r:^[0-9]+$,#{session_name}}" "rename-session \"#{b:session_path}\""' diff --git a/tmux/.local/bin/tmux-clipboard.sh b/tmux/.local/bin/tmux-clipboard.sh new file mode 100755 index 0000000..9d4d993 --- /dev/null +++ b/tmux/.local/bin/tmux-clipboard.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +paste_selection_default="clipboard" +paste_selection_option="@paste_selection" + +custom_paste_command_default="" +custom_paste_command_option="@custom_paste_command" + +get_tmux_option() { + option="$1" + default_value="$2" + option_value=$(tmux show-option -gqv "$option") + if [ -z "$option_value" ]; then + echo "$default_value" + else + echo "$option_value" + fi +} + +paste_selection() { + get_tmux_option "$paste_selection_option" "$paste_selection_default" +} + +custom_paste_cmd() { + get_tmux_option "$custom_paste_command_option" "$custom_paste_command_default" +} + +clipboard_paste_command() { + if [ -n "$(override_paste_cmd)" ]; then + override_paste_cmd + elif command -v pbpaste 1>/dev/null; then + if command -v reattach-to-user-namespace 1>/dev/null; then + echo "reattach-to-user-namespace pbpaste" + else + echo "pbpaste" + fi + elif command -v win32yank.exe 1>/dev/null; then + echo "win32yank.exe -o" + elif [ -n "$DISPLAY" ] && command -v xsel 1>/dev/null; then + echo "xsel -o --$(paste_selection)" + elif [ -n "$DISPLAY" ] && command -v xclip 1>/dev/null; then + echo "xclip -o -selection $(paste_selection)" + elif command -v getclip 1>/dev/null; then + echo "getclip" + elif [ -n "$(custom_paste_cmd)" ]; then + custom_paste_cmd + fi +} + +main() { + paste_command="$(clipboard_paste_command)" + if [ -n "$paste_command" ]; then + tmux set-hook -g client-focus-in "run '$paste_command | tmux load-buffer -b clipboard -'" + fi +} + +main |