1
0
Fork 0
mirror of synced 2024-11-03 01:08:59 -04:00

generalized options affecting bindings by parsing the output of tmux list-keys

and reinjecting modified commands into tmux bind-key, closes #68

applies to:
- tmux_conf_new_window_retain_current_path
- tmux_conf_new_pane_retain_current_path
- tmux_conf_new_pane_reconnect_ssh
- tmux_conf_copy_to_os_clipboard
This commit is contained in:
Gregory Pakosz 2017-05-25 15:15:45 +02:00
parent 264a577ba1
commit 7f48779a22
2 changed files with 87 additions and 60 deletions

View file

@ -54,9 +54,17 @@ set -g visual-activity off
# -- navigation ---------------------------------------------------------------- # -- navigation ----------------------------------------------------------------
# create session
bind C-c new-session
# find session # find session
bind C-f command-prompt -p find-session 'switch-client -t %%' bind C-f command-prompt -p find-session 'switch-client -t %%'
# split current window horizontally
bind - split-window -v
# split current window vertically
bind _ split-window -h
# pane navigation # pane navigation
bind -r h select-pane -L # move left bind -r h select-pane -L # move left
bind -r j select-pane -D # move down bind -r j select-pane -D # move down
@ -125,7 +133,7 @@ run -b 'tmux bind -T copy-mode-vi v send -X begin-selection 2> /dev/null || true
run -b 'tmux bind -t vi-copy C-v rectangle-toggle 2> /dev/null || true' run -b 'tmux bind -t vi-copy C-v rectangle-toggle 2> /dev/null || true'
run -b 'tmux bind -T copy-mode-vi C-v send -X rectangle-toggle 2> /dev/null || true' run -b 'tmux bind -T copy-mode-vi C-v send -X rectangle-toggle 2> /dev/null || true'
run -b 'tmux bind -t vi-copy y copy-selection 2> /dev/null || true' run -b 'tmux bind -t vi-copy y copy-selection 2> /dev/null || true'
run -b 'tmux bind -T copy-mode-vi y send -X copy-selection 2> /dev/null || true' run -b 'tmux bind -T copy-mode-vi y send -X copy-selection-and-cancel 2> /dev/null || true'
run -b 'tmux bind -t vi-copy Escape cancel 2> /dev/null || true' run -b 'tmux bind -t vi-copy Escape cancel 2> /dev/null || true'
run -b 'tmux bind -T copy-mode-vi Escape send -X cancel 2> /dev/null || true' 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 vi-copy H start-of-line 2> /dev/null || true'
@ -577,47 +585,65 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# } # }
# #
# _apply_bindings() { # _apply_bindings() {
# line=$(tmux list-keys | grep new-window | head -1)
# prefix=${line%new-window*}
# column=${#prefix}
#
# tmux_conf_new_window_retain_current_path=${tmux_conf_new_window_retain_current_path:-false} # tmux_conf_new_window_retain_current_path=${tmux_conf_new_window_retain_current_path:-false}
# if _is_enabled "$tmux_conf_new_window_retain_current_path"; then # while IFS= read -r line; do
# tmux bind c new-window -c '#{pane_current_path}' # [ -z "$line" ] && continue
# else # left=$(echo "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g')
# tmux bind c new-window # if _is_enabled "$tmux_conf_new_window_retain_current_path"; then
# fi # right=$(echo "$line" | cut -c"$column-" | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/new-window$/new-window -c "#{pane_current_path}"/g')
# else
# right=$(echo "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/-c[ \t]+"#\{pane_current_path\}"$//g')
# fi
# eval "tmux $left $right"
# done << EOF
# $(tmux list-keys 2>/dev/null | grep -e 'new-window\(\s\+-c\s\+"#{pane_current_path}\|$\)')
# EOF
# #
# tmux_conf_new_pane_retain_current_path=${tmux_conf_new_pane_retain_current_path:-true} # tmux_conf_new_pane_retain_current_path=${tmux_conf_new_pane_retain_current_path:-true}
# while IFS= read -r line; do
# [ -z "$line" ] && continue
# left=$(echo "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g')
# if _is_enabled "$tmux_conf_new_pane_retain_current_path"; then
# right=$(echo "$line" | cut -c"$column-" | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/split-window([ \t]+-(h|v))?$/& -c "#{pane_current_path}"/g')
# else
# right=$(echo "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/-c[ \t]+"#\{pane_current_path\}"$//g')
# fi
# eval "tmux $left $right"
# done << EOF
# $(tmux list-keys 2>/dev/null | grep -e 'split\(-\|_\)window')
# EOF
#
# tmux_conf_new_pane_reconnect_ssh=${tmux_conf_new_pane_reconnect_ssh:-false} # tmux_conf_new_pane_reconnect_ssh=${tmux_conf_new_pane_reconnect_ssh:-false}
# if _is_enabled "$tmux_conf_new_pane_reconnect_ssh"; then # while IFS= read -r line; do
# if _is_enabled "$tmux_conf_new_pane_retain_current_path"; then # [ -z "$line" ] && continue
# tmux bind '"' run "cut -c3- ~/.tmux.conf | sh -s _split_window #{pane_tty} -v -c '#{pane_current_path}'" \;\ # left=$(echo "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g')
# bind % run "cut -c3- ~/.tmux.conf | sh -s _split_window #{pane_tty} -h -c '#{pane_current_path}'" \;\ # if _is_enabled "$tmux_conf_new_pane_reconnect_ssh"; then
# bind - run "cut -c3- ~/.tmux.conf | sh -s _split_window #{pane_tty} -v -c '#{pane_current_path}'" \;\ # right=$(echo "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/split-window([^;]+)/run-shell "cut -c3- ~\/\.tmux\.conf | sh -s _split_window #{pane_tty}\1"/g')
# bind _ run "cut -c3- ~/.tmux.conf | sh -s _split_window #{pane_tty} -h -c '#{pane_current_path}'"
# else # else
# tmux bind '"' run "cut -c3- ~/.tmux.conf | sh -s _split_window #{pane_tty} -v" \;\ # right=$(echo "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/run-shell "cut -c3- ~\/\.tmux\.conf \| sh -s _split_window #\{pane_tty\}([^;]+)"/split-window\1/g' -e 's/#\{.+\}/\"&\"/g')
# bind % run "cut -c3- ~/.tmux.conf | sh -s _split_window #{pane_tty} -h" \;\
# bind - run "cut -c3- ~/.tmux.conf | sh -s _split_window #{pane_tty} -v" \;\
# bind _ run "cut -c3- ~/.tmux.conf | sh -s _split_window #{pane_tty} -h"
# fi # fi
# else # eval "tmux $left $right"
# if _is_enabled "$tmux_conf_new_pane_retain_current_path"; then # done << EOF
# tmux bind '"' split-window -v -c '#{pane_current_path}' \;\ # $(tmux list-keys 2>/dev/null | grep -e 'split\(-\|_\)window')
# bind % split-window -h -c '#{pane_current_path}' \;\ # EOF
# bind - split-window -v -c '#{pane_current_path}' \;\
# bind _ split-window -h -c '#{pane_current_path}'
# else
# tmux bind '"' split-window -v \;\
# bind % split-window -h \;\
# bind - split-window -v \;\
# bind _ split-window -h
# fi
# fi
# #
# tmux_conf_new_session_prompt=${tmux_conf_new_session_prompt:-false} # tmux_conf_new_session_prompt=${tmux_conf_new_session_prompt:-false}
# if _is_enabled "$tmux_conf_new_session_prompt"; then # while IFS= read -r line; do
# tmux bind C-c command-prompt -p new-session 'new-session -s "%%"' # [ -z "$line" ] && continue
# else # left=$(echo "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g')
# tmux bind C-c new-session # if _is_enabled "$tmux_conf_new_session_prompt"; then
# fi # right=$(echo "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/new-session$/command-prompt -p new-session \"new-session -s %%\"/g')
# else
# right=$(echo "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }'| sed -E -e 's/command-prompt -p new-session[^;]+/new-session/g')
# fi
# eval "tmux $left $right"
# done << EOF
# $(tmux list-keys 2>/dev/null | grep -e 'new-session')
# EOF
# #
# if tmux -q -L swap-pane-test -f /dev/null new-session -d \; new-window \; new-window \; swap-pane -t :1 \; kill-session; then # if tmux -q -L swap-pane-test -f /dev/null new-session -d \; new-window \; new-window \; swap-pane -t :1 \; kill-session; then
# tmux bind + run 'cut -c3- ~/.tmux.conf | sh -s _maximize_pane #{session_name} #D' # tmux bind + run 'cut -c3- ~/.tmux.conf | sh -s _maximize_pane #{session_name} #D'
@ -626,32 +652,32 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# fi # fi
# #
# tmux_conf_copy_to_os_clipboard=${tmux_conf_copy_to_os_clipboard:-false} # tmux_conf_copy_to_os_clipboard=${tmux_conf_copy_to_os_clipboard:-false}
# if _is_enabled "$tmux_conf_copy_to_os_clipboard"; then # command -v pbcopy > /dev/null 2>&1 && command='pbcopy'
# if command -v pbcopy > /dev/null 2>&1; then # command -v reattach-to-user-namespace > /dev/null 2>&1 && command='reattach-to-user-namespace pbcopy'
# tmux bind -t vi-copy y copy-pipe 'pbcopy' 2> /dev/null || true # command -v xsel > /dev/null 2>&1 && command='xsel -i -b'
# tmux bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'pbcopy' 2> /dev/null || true # ! command -v xsel > /dev/null 2>&1 && command -v xclip > /dev/null 2>&1 && command='xclip -i -selection clipboard > /dev/null 2>&1'
# fi # command -v clip.exe > /dev/null 2>&1 && command='clip\.exe'
# if command -v reattach-to-user-namespace > /dev/null 2>&1; then # [ -c /dev/clipboard ] && command='cat > \/dev\/clipboard'
# 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 # # shellcheck disable=SC2086
# fi # for table in "" "-t emacs-copy" "-t vi-copy"; do
# if command -v xsel > /dev/null 2>&1; then # line=$(tmux list-keys $table 2>/dev/null | grep -e 'copy-selection\|copy-pipe' | head -1)
# tmux bind -t vi-copy y copy-pipe 'xsel -i -b' 2> /dev/null || true # prefix=${line%copy-*}
# tmux bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'xsel -i -b' 2> /dev/null || true # column=${#prefix}
# fi #
# if ! command -v xsel > /dev/null 2>&1 && command -v xclip > /dev/null 2>&1; then # while IFS= read -r line; do
# tmux bind -t vi-copy y copy-pipe 'xclip -i -selection clipboard > /dev/null 2>&1' 2> /dev/null || true # [ -z "$line" ] && continue
# 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 # left=$(echo "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g')
# fi # if _is_enabled "$tmux_conf_copy_to_os_clipboard"; then
# if command -v clip.exe > /dev/null 2>&1; then # right=$(echo "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e "s/copy-selection(-and-cancel)?$/copy-pipe\1 \"$command\"/g")
# tmux bind -t vi-copy y copy-pipe 'clip.exe' 2> /dev/null || true # else
# tmux bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'clip.exe' 2> /dev/null || true # right=$(echo "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e "s/copy-pipe(-and-cancel)? \"$command\"$/copy-selection\1/g")
# fi # fi
# if [ -c /dev/clipboard ] > /dev/null 2>&1; then # eval "tmux $left $right"
# tmux bind -t vi-copy y copy-pipe 'cat > /dev/clipboard' 2> /dev/null || true # done << EOF
# tmux bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'cat > /dev/clipboard' 2> /dev/null || true # $(tmux list-keys $table 2>/dev/null | grep -e 'copy-selection\|copy-pipe')
# fi # EOF
# fi # done
# } # }
# #
# _apply_theme() { # _apply_theme() {

View file

@ -234,6 +234,7 @@ tmux_conf_theme_clock_style='24'
# in copy mode, copying selection also copies to the OS clipboard # in copy mode, copying selection also copies to the OS clipboard
# - true # - true
# - false (default) # - false (default)
# on macOS, this require installing reattach-to-user-namespace, see README.md
tmux_conf_copy_to_os_clipboard=false tmux_conf_copy_to_os_clipboard=false