diff --git a/.tmux.conf b/.tmux.conf index 6d46f09..58f66ef 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -24,7 +24,7 @@ setw -q -g utf8 on set -g history-limit 5000 # boost history # 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 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() { -# line=$(tmux list-keys | grep new-window | head -1) -# prefix=${line%new-window*} -# column=${#prefix} +# cfg=$(mktemp) && trap 'rm -f $cfg*' EXIT +# +# # 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} -# while IFS= read -r line; do -# [ -z "$line" ] && continue -# left=$(printf '%s' "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g') -# if _is_enabled "$tmux_conf_new_window_retain_current_path"; then -# 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') -# 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/-c[ \t]+"#\{pane_current_path\}"$//g') -# fi -# eval "tmux $left $right" 2>/dev/null || true -# done << EOF -# $(tmux list-keys 2>/dev/null | grep -E 'new-window(\s+-c\s+"#{pane_current_path}"|$)') -# EOF +# if _is_enabled "$tmux_conf_new_window_retain_current_path"; then +# perl -p -i \ +# -e "s/\b(new-window)\b(?!\s+-)/{$&}/g if /\bdisplay-menu\b/" \ +# -e ';' \ +# -e "s/\bnew-window\b(?!([^;}\n\"]*?)(?:\s+-c\s+(\\\?\"?|'?)#\{pane_current_path\}\2))/new-window -c '#{pane_current_path}'/g" \ +# "$cfg" +# else +# perl -p -i -e "s/\bnew-window\b([^;}\n\"]*?)(?:\s+-c\s+(\\\?\"?|'?)#\{pane_current_path\}\2)/new-window\1/g" "$cfg" +# fi # -# 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=$(printf '%s' "$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=$(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') -# 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_retain_current_path=${tmux_conf_new_pane_retain_current_path:-false} +# 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 -c '#{pane_current_path}'/g" "$cfg" +# else +# perl -p -i -e "s/\bsplit-window\b([^;}\n\"]*?)(?:\s+-c\s+(\\\?\"?|'?)#\{pane_current_path\}\2)/split-window\1/g" "$cfg" +# fi # # tmux_conf_new_pane_reconnect_ssh=${tmux_conf_new_pane_reconnect_ssh:-false} -# while IFS= read -r line; do -# [ -z "$line" ] && continue -# left=$(printf '%s' "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g') -# if _is_enabled "$tmux_conf_new_pane_reconnect_ssh"; then -# 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') +# if _is_enabled "$tmux_conf_new_pane_reconnect_ssh"; then +# 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)([^;}\n\"]*)/run-shell 'cut -c3- ~\/\.tmux\.conf | sh -s _split_window #{pane_tty}\1\3 -c #\{pane_current_path\}'/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 -# 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 -# eval "tmux $left $right" 2>/dev/null || true -# done << EOF -# $(tmux list-keys 2>/dev/null | grep -E 'split(-|_)window') -# EOF +# else +# if _is_enabled "$tmux_conf_new_pane_retain_current_path"; then +# 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" +# 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} -# while IFS= read -r line; do -# [ -z "$line" ] && continue -# left=$(printf '%s' "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g') -# if _is_enabled "$tmux_conf_new_session_prompt"; then -# 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') -# 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/command-prompt -p new-session[^;]+/new-session/g') -# fi -# eval "tmux $left $right" 2>/dev/null || true -# done << EOF -# $(tmux list-keys 2>/dev/null | grep 'new-session') -# EOF +# if _is_enabled "$tmux_conf_new_session_prompt"; then +# perl -p -i \ +# -e "s/(? /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' # # if [ -n "$command" ]; then -# # shellcheck disable=SC2086 -# for table in "" "-t emacs-copy" "-t vi-copy"; do -# line=$(tmux list-keys $table 2>/dev/null | grep -E 'copy-selection|copy-pipe' | head -1) -# [ -z "$line" ] && continue -# prefix=${line%copy-*} -# column=${#prefix} +# if _is_enabled "$tmux_conf_copy_to_os_clipboard"; then +# perl -p -i -e "s/\bcopy-selection(-and-cancel)?\b/copy-pipe\1 '$command'/g" "$cfg" +# else +# perl -p -i -e "s/\bcopy-pipe(-and-cancel)?\b\s+(\"|')?$command\2/copy-selection\1/g" "$cfg" +# fi +# fi # -# while IFS= read -r line; do -# [ -z "$line" ] && continue -# left=$(printf '%s' "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g') -# if _is_enabled "$tmux_conf_copy_to_os_clipboard"; then -# 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") -# 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 +# # ignore bindings with errors +# while ! out=$(tmux source-file "$cfg"); do +# line=$(printf "%s" "$out" | cut -d':' -f2) +# perl -n -i -e "if ($. != $line) { print }" "$cfg" +# done # } # # _apply_theme() {