rewrote _apply_bindings() to support new tmux 3.0 bindings, fixes #254
moved away from the eval madness, now current bindings are saved to a temporary file before being altered with perl
This commit is contained in:
parent
01c91ba523
commit
a9b526c9a2
1 changed files with 64 additions and 71 deletions
135
.tmux.conf
135
.tmux.conf
|
@ -24,7 +24,7 @@ setw -q -g utf8 on
|
||||||
set -g history-limit 5000 # boost history
|
set -g history-limit 5000 # boost history
|
||||||
|
|
||||||
# edit configuration
|
# edit configuration
|
||||||
bind e new-window -n '~/.tmux.conf.local' "sh -c '\${EDITOR:-vim} ~/.tmux.conf.local && tmux source ~/.tmux.conf && tmux display \"~/.tmux.conf sourced\"'"
|
bind e new-window -n "~/.tmux.conf.local" "sh -c '\${EDITOR:-vim} ~/.tmux.conf.local && tmux source ~/.tmux.conf && tmux display \"~/.tmux.conf sourced\"'"
|
||||||
|
|
||||||
# reload configuration
|
# reload configuration
|
||||||
bind r source-file ~/.tmux.conf \; display '~/.tmux.conf sourced'
|
bind r source-file ~/.tmux.conf \; display '~/.tmux.conf sourced'
|
||||||
|
@ -680,65 +680,67 @@ run -b '[ -z "#{session_id}" ] && [ -z "#{version}" ] && tmux set display-time 3
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
# _apply_bindings() {
|
# _apply_bindings() {
|
||||||
# line=$(tmux list-keys | grep new-window | head -1)
|
# cfg=$(mktemp) && trap 'rm -f $cfg*' EXIT
|
||||||
# prefix=${line%new-window*}
|
#
|
||||||
# column=${#prefix}
|
# # until tmux >= 3.0, output of tmux list-keys can't be consumed back by tmux source-file without applying some escapings
|
||||||
|
# tmux list-keys | grep -vF 'tmux.conf.local' | grep -E '(new-window|split(-|_)window|new-session|copy-selection|copy-pipe)' | awk \
|
||||||
|
# '{i = $2 == "-T" ? 4 : 5; gsub(/^[;]$/, "\\\\&", $i); gsub(/^[$"#~]$/, "'"'"'&'"'"'", $i); gsub(/^['"'"']$/, "\"&\"", $i); print}' > "$cfg"
|
||||||
|
#
|
||||||
|
# # tmux 3.0 doesn't include 02254d1e5c881be95fd2fc37b4c4209640b6b266 and the
|
||||||
|
# # output of list-keys can be truncated
|
||||||
|
# perl -p -i -e "s/'#\{\?window_zoomed_flag,Unzoom,Zoom\}' 'z' \{resize-pane -$/'#{?window_zoomed_flag,Unzoom,Zoom}' 'z' {resize-pane -Z}\"/g" "$cfg"
|
||||||
#
|
#
|
||||||
# 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}
|
||||||
# while IFS= read -r line; do
|
# if _is_enabled "$tmux_conf_new_window_retain_current_path"; then
|
||||||
# [ -z "$line" ] && continue
|
# perl -p -i \
|
||||||
# left=$(printf '%s' "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g')
|
# -e "s/\b(new-window)\b(?!\s+-)/{$&}/g if /\bdisplay-menu\b/" \
|
||||||
# if _is_enabled "$tmux_conf_new_window_retain_current_path"; then
|
# -e ';' \
|
||||||
# right=$(printf '%s' "$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')
|
# -e "s/\bnew-window\b(?!([^;}\n\"]*?)(?:\s+-c\s+(\\\?\"?|'?)#\{pane_current_path\}\2))/new-window -c '#{pane_current_path}'/g" \
|
||||||
# else
|
# "$cfg"
|
||||||
# right=$(printf '%s' "$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')
|
# else
|
||||||
# fi
|
# perl -p -i -e "s/\bnew-window\b([^;}\n\"]*?)(?:\s+-c\s+(\\\?\"?|'?)#\{pane_current_path\}\2)/new-window\1/g" "$cfg"
|
||||||
# eval "tmux $left $right" 2>/dev/null || true
|
# fi
|
||||||
# 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:-false}
|
||||||
# while IFS= read -r line; do
|
# if _is_enabled "$tmux_conf_new_pane_retain_current_path"; then
|
||||||
# [ -z "$line" ] && continue
|
# perl -p -i -e "s/\bsplit-window\b(?!([^;}\n\"]*?)(?:\s+-c\s+(\\\?\"?|'?)#\{pane_current_path\}\2))/split-window -c '#{pane_current_path}'/g" "$cfg"
|
||||||
# left=$(printf '%s' "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g')
|
# else
|
||||||
# if _is_enabled "$tmux_conf_new_pane_retain_current_path"; then
|
# perl -p -i -e "s/\bsplit-window\b([^;}\n\"]*?)(?:\s+-c\s+(\\\?\"?|'?)#\{pane_current_path\}\2)/split-window\1/g" "$cfg"
|
||||||
# right=$(printf '%s' "$line" | cut -c"$column-" | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e '/#\{pane_current_path\}/!s/split(-|_)window([ \t]+#\{pane_tty\})?([ \t]+-(h|v))?/& -c "#{pane_current_path}"/g')
|
# fi
|
||||||
# else
|
|
||||||
# right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/[ \t]+(-c[ \t]+(\\")?"#\{pane_current_path\}"(\\")?|-c #\{pane_current_path\})//g')
|
|
||||||
# fi
|
|
||||||
# eval "tmux $left $right" 2>/dev/null || true
|
|
||||||
# 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}
|
||||||
# while IFS= read -r line; do
|
# if _is_enabled "$tmux_conf_new_pane_reconnect_ssh"; then
|
||||||
# [ -z "$line" ] && continue
|
# if _is_enabled "$tmux_conf_new_pane_retain_current_path"; then
|
||||||
# left=$(printf '%s' "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g')
|
# perl -p -i \
|
||||||
# if _is_enabled "$tmux_conf_new_pane_reconnect_ssh"; then
|
# -e "s/\bsplit-window\b([^;}\n\"]*?)(?:\s+-c\s+(\\\?\"?|'?)#\{pane_current_path\}\2)([^;}\n\"]*)/run-shell 'cut -c3- ~\/\.tmux\.conf | sh -s _split_window #{pane_tty}\1\3 -c #\{pane_current_path\}'/g" \
|
||||||
# right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e '/_split_window/!s/"/\\"/g' -e 's/split-window([^;]*)/run-shell "cut -c3- ~\/\.tmux\.conf | sh -s _split_window #{pane_tty}\1"/g')
|
# -e ';' \
|
||||||
|
# -e "s/\b_split_window\b\s+#\{pane_tty\}(.*?)\s+-c\s+\\\\\"#\{pane_current_path\}\\\\\"\"/_split_window #{pane_tty}\1 -c \\\\\"#{pane_current_path}\\\\\"\"/g" \
|
||||||
|
# "$cfg"
|
||||||
# else
|
# else
|
||||||
# right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/\\"/"/g' -e 's/run-shell "cut -c3- ~\/\.tmux\.conf \| sh -s _split_window #\{pane_tty\}([^;]*)"/split-window\1/g' -e 's/#\{.+\}/\"&\"/g')
|
# perl -p -i \
|
||||||
|
# -e "s/\bsplit-window\b([^;}\n]*)/run-shell 'cut -c3- ~\/\.tmux\.conf | sh -s _split_window #{pane_tty}\1'/g" \
|
||||||
|
# -e ';' \
|
||||||
|
# -e "s/\b_split_window\b\s+#\{pane_tty\}(.*?)\s+-c\s+\\\\\"#\{pane_current_path\}\\\\\"\"/_split_window #{pane_tty}\1\"/g" \
|
||||||
|
# "$cfg"
|
||||||
# fi
|
# fi
|
||||||
# eval "tmux $left $right" 2>/dev/null || true
|
# else
|
||||||
# done << EOF
|
# if _is_enabled "$tmux_conf_new_pane_retain_current_path"; then
|
||||||
# $(tmux list-keys 2>/dev/null | grep -E 'split(-|_)window')
|
# perl -p -i -e "s/\brun-shell\b(\s+(\"|')cut\s+-c3-\s+~\/\.tmux\.conf\s+\|\s+sh\s+-s\s+_split_window\s+#\{pane_tty\})(.*?)\s+-c\s+#\{pane_current_path\}\2/split-window\3 -c '#{pane_current_path}'/g" "$cfg"
|
||||||
# EOF
|
# else
|
||||||
|
# perl -p -i -e "s/\brun-shell\b(\s+(\"|')cut\s+-c3-\s+~\/\.tmux\.conf\s+\|\s+sh\s+-s\s+_split_window\s+#\{pane_tty\})(.*)\2/split-window\3/g" "$cfg"
|
||||||
|
# fi
|
||||||
|
# fi
|
||||||
#
|
#
|
||||||
# tmux_conf_new_session_prompt=${tmux_conf_new_session_prompt:-false}
|
# tmux_conf_new_session_prompt=${tmux_conf_new_session_prompt:-false}
|
||||||
# while IFS= read -r line; do
|
# if _is_enabled "$tmux_conf_new_session_prompt"; then
|
||||||
# [ -z "$line" ] && continue
|
# perl -p -i \
|
||||||
# left=$(printf '%s' "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g')
|
# -e "s/(?<!command-prompt -p )\b(new-session)\b(?!\s+-)/{$&}/g if /\bdisplay-menu\b/" \
|
||||||
# if _is_enabled "$tmux_conf_new_session_prompt"; then
|
# -e ';' \
|
||||||
# right=$(printf '%s' "$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')
|
# -e "s/(?<!\bcommand-prompt -p )\bnew-session\b(?! -s)/command-prompt -p new-session 'new-session -s \"%%\"'/g" \
|
||||||
# else
|
# "$cfg"
|
||||||
# right=$(printf '%s' "$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')
|
# else
|
||||||
# fi
|
# perl -p -i -e "s/\bcommand-prompt\s+-p\s+new-session\s+'new-session\s+-s\s+\"%%\"'/new-session/g" "$cfg"
|
||||||
# eval "tmux $left $right" 2>/dev/null || true
|
# fi
|
||||||
# done << EOF
|
|
||||||
# $(tmux list-keys 2>/dev/null | grep 'new-session')
|
|
||||||
# EOF
|
|
||||||
#
|
#
|
||||||
# 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}
|
||||||
# command -v pbcopy > /dev/null 2>&1 && command='pbcopy'
|
# command -v pbcopy > /dev/null 2>&1 && command='pbcopy'
|
||||||
|
@ -749,27 +751,18 @@ run -b '[ -z "#{session_id}" ] && [ -z "#{version}" ] && tmux set display-time 3
|
||||||
# [ -c /dev/clipboard ] && command='cat > \/dev\/clipboard'
|
# [ -c /dev/clipboard ] && command='cat > \/dev\/clipboard'
|
||||||
#
|
#
|
||||||
# if [ -n "$command" ]; then
|
# if [ -n "$command" ]; then
|
||||||
# # shellcheck disable=SC2086
|
# if _is_enabled "$tmux_conf_copy_to_os_clipboard"; then
|
||||||
# for table in "" "-t emacs-copy" "-t vi-copy"; do
|
# perl -p -i -e "s/\bcopy-selection(-and-cancel)?\b/copy-pipe\1 '$command'/g" "$cfg"
|
||||||
# line=$(tmux list-keys $table 2>/dev/null | grep -E 'copy-selection|copy-pipe' | head -1)
|
# else
|
||||||
# [ -z "$line" ] && continue
|
# perl -p -i -e "s/\bcopy-pipe(-and-cancel)?\b\s+(\"|')?$command\2/copy-selection\1/g" "$cfg"
|
||||||
# prefix=${line%copy-*}
|
# fi
|
||||||
# column=${#prefix}
|
# fi
|
||||||
#
|
#
|
||||||
# while IFS= read -r line; do
|
# # ignore bindings with errors
|
||||||
# [ -z "$line" ] && continue
|
# while ! out=$(tmux source-file "$cfg"); do
|
||||||
# left=$(printf '%s' "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g')
|
# line=$(printf "%s" "$out" | cut -d':' -f2)
|
||||||
# if _is_enabled "$tmux_conf_copy_to_os_clipboard"; then
|
# perl -n -i -e "if ($. != $line) { print }" "$cfg"
|
||||||
# right=$(printf '%s' "$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")
|
# done
|
||||||
# else
|
|
||||||
# right=$(printf '%s' "$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
|
|
||||||
# eval "tmux $left $right" 2>/dev/null || true
|
|
||||||
# done << EOF
|
|
||||||
# $(tmux list-keys $table 2>/dev/null | grep -E 'copy-selection|copy-pipe')
|
|
||||||
# EOF
|
|
||||||
# done
|
|
||||||
# fi
|
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
# _apply_theme() {
|
# _apply_theme() {
|
||||||
|
|
Loading…
Reference in a new issue