From 264a577ba183bf7ce74da22a18fbb1bdba8244bf Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Wed, 17 May 2017 22:23:23 +0200 Subject: [PATCH] added tmux_conf_copy_to_os_clipboard variable, closes #75 When true, copying selection with y in copy mode also sends selection to the OS clipboard. --- .tmux.conf | 38 ++++++++++++++++++++++++++++++++++++-- .tmux.conf.local | 10 +++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index 8367567..3f8d2ef 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -131,8 +131,14 @@ run -b 'tmux bind -T copy-mode-vi Escape send -X cancel 2> /dev/null || true' run -b 'tmux bind -t vi-copy H start-of-line 2> /dev/null || true' run -b 'tmux bind -T copy-mode-vi L send -X end-of-line 2> /dev/null || true' -# copy to Mac OSX pasteboard -if -b 'command -v reattach-to-user-namespace > /dev/null 2>&1' 'bind y run "tmux save-buffer - | reattach-to-user-namespace pbcopy"' +# copy to Mac OSX clipboard +if -b 'command -v reattach-to-user-namespace > /dev/null 2>&1' 'bind y run -b "tmux save-buffer - | reattach-to-user-namespace pbcopy"' +# copy to X11 clipboard +if -b 'command -v xsel > /dev/null 2>&1' 'bind y run -b "tmux save-buffer - | xsel -i -b"' +if -b '! command -v xsel > /dev/null 2>&1 && command -v xclip > /dev/null 2>&1' 'bind y run -b "tmux save-buffer - | xclip -i -selection clipboard >/dev/null 2>&1"' +# copy to Windows clipboard +if -b 'command -v clip.exe > /dev/null 2>&1' 'bind y run -b "tmux save-buffer - | clip.exe"' +if -b '[ -c /dev/clipboard ]' 'bind y run -b "tmux save-buffer - > /dev/clipboard"' # -- user defined overrides ---------------------------------------------------- @@ -618,6 +624,34 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # else # tmux bind + display 'your tmux version has a buggy swap-pane command - see ticket #108, fixed in upstream commit 78e783e' # fi +# +# tmux_conf_copy_to_os_clipboard=${tmux_conf_copy_to_os_clipboard:-false} +# if _is_enabled "$tmux_conf_copy_to_os_clipboard"; then +# if command -v pbcopy > /dev/null 2>&1; then +# tmux bind -t vi-copy y copy-pipe 'pbcopy' 2> /dev/null || true +# tmux bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'pbcopy' 2> /dev/null || true +# fi +# if command -v reattach-to-user-namespace > /dev/null 2>&1; then +# tmux bind -t vi-copy y copy-pipe 'reattach-to-user-namespace pbcopy' 2> /dev/null || true +# tmux bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'reattach-to-user-namespace pbcopy' 2> /dev/null || true +# fi +# if command -v xsel > /dev/null 2>&1; then +# tmux bind -t vi-copy y copy-pipe 'xsel -i -b' 2> /dev/null || true +# tmux bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'xsel -i -b' 2> /dev/null || true +# fi +# if ! command -v xsel > /dev/null 2>&1 && command -v xclip > /dev/null 2>&1; then +# tmux bind -t vi-copy y copy-pipe 'xclip -i -selection clipboard > /dev/null 2>&1' 2> /dev/null || true +# tmux bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'xclip -i -selection clipboard > /dev/null 2>&1' 2> /dev/null || true +# fi +# if command -v clip.exe > /dev/null 2>&1; then +# tmux bind -t vi-copy y copy-pipe 'clip.exe' 2> /dev/null || true +# tmux bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'clip.exe' 2> /dev/null || true +# fi +# if [ -c /dev/clipboard ] > /dev/null 2>&1; then +# tmux bind -t vi-copy y copy-pipe 'cat > /dev/clipboard' 2> /dev/null || true +# tmux bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'cat > /dev/clipboard' 2> /dev/null || true +# fi +# fi # } # # _apply_theme() { diff --git a/.tmux.conf.local b/.tmux.conf.local index 1d1e2a3..d187144 100644 --- a/.tmux.conf.local +++ b/.tmux.conf.local @@ -229,7 +229,15 @@ tmux_conf_theme_clock_colour='#00afff' # light blue tmux_conf_theme_clock_style='24' -# ------------------------------------------------------------------------------ +# -- clipboard ----------------------------------------------------------------- + +# in copy mode, copying selection also copies to the OS clipboard +# - true +# - false (default) +tmux_conf_copy_to_os_clipboard=false + + +# -- user customizations ------------------------------------------------------- # this is the place to override or undo settings # increase history size