From a9b526c9a20619840cd1e08b8e0dcbae4486f944 Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Wed, 27 Nov 2019 12:58:38 +0100 Subject: [PATCH 01/12] 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 --- .tmux.conf | 135 +++++++++++++++++++++++++---------------------------- 1 file changed, 64 insertions(+), 71 deletions(-) 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() { From 489cde73fcddde1a84f622aaf81d09c23ae655a5 Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Fri, 29 Nov 2019 21:15:07 +0100 Subject: [PATCH 02/12] fixed broken status line separator default values --- .tmux.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index 58f66ef..ac4006c 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -810,10 +810,10 @@ run -b '[ -z "#{session_id}" ] && [ -z "#{version}" ] && tmux set display-time 3 # # # -- status line ------------------------------------------------------- # -# tmux_conf_theme_left_separator_main=$(_decode_unicode_escapes "${tmux_conf_theme_left_separator_main-''}") -# tmux_conf_theme_left_separator_sub=$(_decode_unicode_escapes "${tmux_conf_theme_left_separator_sub-'|'}") -# tmux_conf_theme_right_separator_main=$(_decode_unicode_escapes "${tmux_conf_theme_right_separator_main-''}") -# tmux_conf_theme_right_separator_sub=$(_decode_unicode_escapes "${tmux_conf_theme_right_separator_sub-'|'}") +# tmux_conf_theme_left_separator_main=$(_decode_unicode_escapes "${tmux_conf_theme_left_separator_main-}") +# tmux_conf_theme_left_separator_sub=$(_decode_unicode_escapes "${tmux_conf_theme_left_separator_sub-|}") +# tmux_conf_theme_right_separator_main=$(_decode_unicode_escapes "${tmux_conf_theme_right_separator_main-}") +# tmux_conf_theme_right_separator_sub=$(_decode_unicode_escapes "${tmux_conf_theme_right_separator_sub-|}") # # tmux_conf_theme_message_fg=${tmux_conf_theme_message_fg:-'#000000'} # black # tmux_conf_theme_message_bg=${tmux_conf_theme_message_bg:-'#ffff00'} # yellow From c94f05f044484f1c72002229c254cc1196e16ac7 Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Fri, 29 Nov 2019 21:27:50 +0100 Subject: [PATCH 03/12] rewrote _apply_bindings() to support new tmux 3.0 bindings (2) patch the output of 'tmux list-keys' right before sourcing back --- .tmux.conf | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index ac4006c..9cf02fb 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -682,9 +682,7 @@ run -b '[ -z "#{session_id}" ] && [ -z "#{version}" ] && tmux set display-time 3 # _apply_bindings() { # 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 list-keys | grep -vF 'tmux.conf.local' | grep -E '(new-window|split(-|_)window|new-session|copy-selection|copy-pipe)' > "$cfg" # # # tmux 3.0 doesn't include 02254d1e5c881be95fd2fc37b4c4209640b6b266 and the # # output of list-keys can be truncated @@ -758,6 +756,10 @@ run -b '[ -z "#{session_id}" ] && [ -z "#{version}" ] && tmux set display-time 3 # fi # fi # +# # until tmux >= 3.0, output of tmux list-keys can't be consumed back by tmux source-file without applying some escapings +# awk < "$cfg" \ +# '{i = $2 == "-T" ? 4 : 5; gsub(/^[;]$/, "\\\\&", $i); gsub(/^[$"#~]$/, "'"'"'&'"'"'", $i); gsub(/^['"'"']$/, "\"&\"", $i); print}' > "$cfg" +# # # ignore bindings with errors # while ! out=$(tmux source-file "$cfg"); do # line=$(printf "%s" "$out" | cut -d':' -f2) From 12311556006088e290371c62c450574d15e56b4f Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Sat, 30 Nov 2019 15:48:04 +0100 Subject: [PATCH 04/12] warn users about tmux >= 2.4 only when starting tmux --- .tmux.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.tmux.conf b/.tmux.conf index 9cf02fb..ab46da8 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -168,7 +168,7 @@ if '[ -f ~/.tmux.conf.local ]' 'source ~/.tmux.conf.local' # -- 8< ------------------------------------------------------------------------ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' -run -b '[ -z "#{session_id}" ] && [ -z "#{version}" ] && tmux set display-time 3000 \; display "This configuration will soon require tmux >= 2.4" \; set -u display-time || true' +run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-time 3000 \; display "This configuration will soon require tmux >= 2.4" \; set -u display-time || true' # EOF From 6815beef4f302d5a04d43fb4c966c660a7cc041f Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Sat, 30 Nov 2019 15:48:40 +0100 Subject: [PATCH 05/12] afer the _apply_bindings() rewrite, perl has become mandatory --- .tmux.conf | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index ab46da8..03d1777 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -206,23 +206,9 @@ run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-tim # fi # } # -# if command -v perl > /dev/null 2>&1; then -# _decode_unicode_escapes() { -# printf '%s' "$*" | perl -CS -pe 's/(\\u([0-9A-Fa-f]{1,4})|\\U([0-9A-Fa-f]{1,8}))/chr(hex($2.$3))/eg' 2>/dev/null -# } -# elif bash --norc --noprofile -c '[[ ! $BASH_VERSION < 4.2. ]]' > /dev/null 2>&1; then -# _decode_unicode_escapes() { -# bash --norc --noprofile -c "printf '%b' '$*'" -# } -# elif command -v python > /dev/null 2>&1; then -# _decode_unicode_escapes() { -# python -c "import re; import sys; sys.stdout.write(re.sub(r'\\\U([0-9A-Fa-f]{1,8})', lambda match: r'\U%s' % match.group(1).zfill(8), r'$*').encode().decode('unicode-escape', 'ignore'))" -# } -# else -# _decode_unicode_escapes() { -# printf '%b' "$*" -# } -# fi +# _decode_unicode_escapes() { +# printf '%s' "$*" | perl -CS -pe 's/(\\u([0-9A-Fa-f]{1,4})|\\U([0-9A-Fa-f]{1,8}))/chr(hex($2.$3))/eg' 2>/dev/null +# } # # _maximize_pane() { # current_session=${1:-$(tmux display -p '#{session_name}')} From 92ed64959726240f9af696507686c3a9fa97eead Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Sat, 30 Nov 2019 15:49:06 +0100 Subject: [PATCH 06/12] made requirements explicit in both README.md and .tmux.conf --- .tmux.conf | 13 +++++++++++++ README.md | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index 03d1777..883038e 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -1175,6 +1175,19 @@ run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-tim # # _apply_configuration() { # +# if ! command -v perl > /dev/null 2>&1; then +# tmux run -b 'tmux set display-time 3000 \; display "This configuration requires perl" \; set -u display-time' +# return +# fi +# if ! command -v sed > /dev/null 2>&1; then +# tmux run -b 'tmux set display-time 3000 \; display "This configuration requires sed" \; set -u display-time' +# return +# fi +# if ! command -v awk > /dev/null 2>&1; then +# tmux run -b 'tmux set display-time 3000 \; display "This configuration requires awk" \; set -u display-time' +# return +# fi +# # # see https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard # if command -v reattach-to-user-namespace > /dev/null 2>&1; then # default_shell="$(tmux show -gv default-shell)" diff --git a/README.md b/README.md index e763c3d..470007d 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,9 @@ Installation Requirements: - - tmux **`>= 2.1`** running inside Linux, Mac, OpenBSD, Cygwin or WSL (Bash on - Ubuntu on Windows) + - tmux **`>= 2.1`** (soon `>= 2.4`) running inside Linux, Mac, OpenBSD, Cygwin + or WSL + - awk, perl and sed - outside of tmux, `$TERM` must be set to `xterm-256color` To install, run the following from your terminal: (you may want to backup your From 1cf813fa8bfdd5ae96f82bda8231692c85c5beda Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Sat, 30 Nov 2019 19:50:58 +0100 Subject: [PATCH 07/12] rewrote _apply_bindings() to support new tmux 3.0 bindings (3) reading and writing to the modified list-keys' output gave the illusion it worked --- .tmux.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index 883038e..4333ddf 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -744,12 +744,12 @@ run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-tim # # # until tmux >= 3.0, output of tmux list-keys can't be consumed back by tmux source-file without applying some escapings # awk < "$cfg" \ -# '{i = $2 == "-T" ? 4 : 5; gsub(/^[;]$/, "\\\\&", $i); gsub(/^[$"#~]$/, "'"'"'&'"'"'", $i); gsub(/^['"'"']$/, "\"&\"", $i); print}' > "$cfg" +# '{i = $2 == "-T" ? 4 : 5; gsub(/^[;]$/, "\\\\&", $i); gsub(/^[$"#~]$/, "'"'"'&'"'"'", $i); gsub(/^['"'"']$/, "\"&\"", $i); print}' > "$cfg.in" # # # 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" +# perl -n -i -e "if ($. != $line) { print }" "$cfg.in" # done # } # From f4fc2730cf1a2ae26ebf3707548945a73cd74ff1 Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Sun, 1 Dec 2019 13:43:58 +0100 Subject: [PATCH 08/12] rewrote _apply_bindings() to support new tmux 3.0 bindings (4) failed to source the proper modified file, fixes #303 --- .tmux.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.tmux.conf b/.tmux.conf index 4333ddf..de35325 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -747,7 +747,7 @@ run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-tim # '{i = $2 == "-T" ? 4 : 5; gsub(/^[;]$/, "\\\\&", $i); gsub(/^[$"#~]$/, "'"'"'&'"'"'", $i); gsub(/^['"'"']$/, "\"&\"", $i); print}' > "$cfg.in" # # # ignore bindings with errors -# while ! out=$(tmux source-file "$cfg"); do +# while ! out=$(tmux source-file "$cfg.in"); do # line=$(printf "%s" "$out" | cut -d':' -f2) # perl -n -i -e "if ($. != $line) { print }" "$cfg.in" # done From a83ba39f09534c2df8f9e94e48174d67be030976 Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Sat, 29 Feb 2020 20:15:54 +0100 Subject: [PATCH 09/12] fixed _tty_info() to properly discard daemons and their children, fixes #320 --- .tmux.conf | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index de35325..fa47bee 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -480,9 +480,13 @@ run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-tim # user[$2] = $1; parent[$2] = $3; child[$3] = $2 # } # END { -# for (i in user) +# for (i in parent) # { -# if (!(i in child) && parent[i] != 1) +# j = i +# while (parent[j]) +# j = parent[j] +# +# if (!(i in child) && j != 1) # { # file = "/proc/" i "/cmdline"; getline command < file; close(file) # gsub(/\0/, " ", command) @@ -500,7 +504,11 @@ run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-tim # END { # for (i in parent) # { -# if (!(i in child) && parent[i] != 1) +# j = i +# while (parent[j]) +# j = parent[j] +# +# if (!(i in child) && j != 1) # { # print i, user[i], command[i] # exit From 57eeffcf0e5b356b9cda27aa44edbf2c849103eb Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Wed, 11 Mar 2020 15:10:51 +0100 Subject: [PATCH 10/12] raised _maximize_pane() retry count and sleep duration, fixes #328 this helps when running under WSL where fork() is slow --- .tmux.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index fa47bee..2353a5f 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -222,9 +222,9 @@ run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-tim # window=$(tmux new-window -t "$current_session:" -P "exec maximized... 2> /dev/null & tmux setw -t \"$current_session:\" remain-on-exit on; printf \"Pane has been maximized, press + to restore. %s\" '$current_pane'") # window=${window%.*} # -# retry=10 +# retry=1000 # while [ x"$(tmux list-panes -t "$window" -F '#{session_name}:#{window_index} #{pane_dead}' 2>/dev/null)" != x"$window 1" ] && [ "$retry" -ne 0 ]; do -# sleep 0.05 +# sleep 0.1 # retry=$((retry - 1)) # done # if [ "$retry" -eq 0 ]; then From 4919400fe2a8144c4bab19628bf5f5dec363877a Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Tue, 17 Mar 2020 19:54:06 +0100 Subject: [PATCH 11/12] improved error bypass logic in _apply_bindings(), fixes #330 --- .tmux.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index 2353a5f..becc718 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -755,8 +755,8 @@ run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-tim # '{i = $2 == "-T" ? 4 : 5; gsub(/^[;]$/, "\\\\&", $i); gsub(/^[$"#~]$/, "'"'"'&'"'"'", $i); gsub(/^['"'"']$/, "\"&\"", $i); print}' > "$cfg.in" # # # ignore bindings with errors -# while ! out=$(tmux source-file "$cfg.in"); do -# line=$(printf "%s" "$out" | cut -d':' -f2) +# while ! out=$(tmux source-file -v "$cfg.in"); do +# line=$(printf "%s" "$out" | tail -1 | cut -d':' -f2) # perl -n -i -e "if ($. != $line) { print }" "$cfg.in" # done # } From d6f0f647dd68561ed010f83d8d226383aebfb805 Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Wed, 18 Mar 2020 14:25:40 +0100 Subject: [PATCH 12/12] improved error bypass logic in _apply_bindings() (2), fixes #331 source-file -v is not documented in tmux CHANGES but in fact appeared in tmux 3.0 --- .tmux.conf | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index becc718..5c7aad5 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -755,10 +755,13 @@ run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-tim # '{i = $2 == "-T" ? 4 : 5; gsub(/^[;]$/, "\\\\&", $i); gsub(/^[$"#~]$/, "'"'"'&'"'"'", $i); gsub(/^['"'"']$/, "\"&\"", $i); print}' > "$cfg.in" # # # ignore bindings with errors -# while ! out=$(tmux source-file -v "$cfg.in"); do -# line=$(printf "%s" "$out" | tail -1 | cut -d':' -f2) -# perl -n -i -e "if ($. != $line) { print }" "$cfg.in" -# done +# if ! tmux source-file "$cfg.in"; then +# verbose_flag=$(tmux source-file -v /dev/null 2> /dev/null && printf -- '-v' || true) +# while ! out=$(tmux source-file "$verbose_flag" "$cfg.in"); do +# line=$(printf "%s" "$out" | tail -1 | cut -d':' -f2) +# perl -n -i -e "if ($. != $line) { print }" "$cfg.in" +# done +# fi # } # # _apply_theme() {