From e865a8a1c1fd4f3e2ca0e3f45aab9e1ccabbead1 Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Thu, 14 Jul 2022 16:26:48 +0200 Subject: [PATCH] added a way to selectively disable binding manipulation, closes #514 you can set the following variables to 'disabled': - tmux_conf_new_window_retain_current_path - tmux_conf_new_pane_retain_current_path - tmux_conf_new_pane_reconnect_ssh - tmux_conf_new_session_prompt - tmux_conf_copy_to_os_clipboard --- .tmux.conf | 70 +++++++++++++++++++++++++++++------------------- .tmux.conf.local | 7 ++++- 2 files changed, 49 insertions(+), 28 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index 420ddee..53d0bc6 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -196,8 +196,16 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # # _tmux_version=$(tmux -V | awk '{gsub(/[^0-9.]/, "", $2); print ($2+0) * 100}') # +# _is_true() { +# [ x"$1" = x"true" ] || [ x"$1" = x"yes" ] || [ x"$1" = x"1" ] +# } +# # _is_enabled() { -# [ x"$1" = x"true" ] || [ x"$1" = x"yes" ] || [ x"$1" = x"enabled" ] || [ x"$1" = x"1" ] +# [ x"$1" = x"enabled" ] +# } +# +# _is_disabled() { +# [ x"$1" = x"disabled" ] # } # # _circled() { @@ -580,7 +588,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # [ -z "$username" ] && username=$(ssh $ssh_or_mosh_args -T -o ControlPath=none -o ProxyCommand="sh -c 'echo %%username%% %r >&2'" 2>&1 | awk '/^%username% / { print $2; exit }') # [ -z "$username" ] && username=$(ssh $ssh_or_mosh_args -v -T -o ControlPath=none -o ProxyCommand=false -o IdentityFile='%%username%%/%r' 2>&1 | awk '/%username%/ { print substr($4,12); exit }') # else -# if ! _is_enabled "$ssh_only"; then +# if ! _is_true "$ssh_only"; then # username=${pane_info#*:} # username=${username%%:*} # fi @@ -607,7 +615,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # # shellcheck disable=SC2086 # [ -z "$hostname" ] && hostname=$(ssh -T -o ControlPath=none -o ProxyCommand="sh -c 'echo %%hostname%% %h >&2'" $ssh_or_mosh_args 2>&1 | awk '/^%hostname% / { print $2; exit }') # -# if ! _is_enabled "$full"; then +# if ! _is_true "$full"; then # case "$hostname" in # *[a-z-].*) # hostname=${hostname%%.*} @@ -618,7 +626,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # esac # fi # else -# if ! _is_enabled "$ssh_only"; then +# if ! _is_true "$ssh_only"; then # hostname="$h_or_H" # fi # fi @@ -723,7 +731,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # if [ x"$apply_overrides" = x"" ] && [ x"$(tput colors)" = x"16777216" ]; then # apply_overrides=true # fi -# elif _is_enabled "$tmux_conf_24b_colour"; then +# elif _is_true "$tmux_conf_24b_colour"; then # apply_overrides=true # fi # if [ x"$apply_overrides" = x"true" ]; then @@ -746,36 +754,44 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # # 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" # -# perl -p -i -e " -# s/\bnew-window\b([^;}\n]*?)(?:\s+-c\s+((?:\\\\\")?|\"?|'?)#\{pane_current_path\}\2)/new-window\1/g -# ; -# s/\brun-shell\b\s+(\"|')cut\s+-c3-\s+~\/\.tmux\.conf\s+\|\s+sh\s+-s\s+_split_window\s+#\{b:pane_tty\}([^\n\1]*)(\s+-c\s+((?:\\\\\")?|\"?|'?)#\{pane_current_path\}\4)([^\n\1]*)\1/run-shell \1cut -c3- ~\/.tmux.conf | sh -s _split_window #{pane_pid} #{b:pane_tty}\2\5\1/g -# ; -# s/\brun-shell\b(\s+((?:\\\\\")?|\"?|'?)cut\s+-c3-\s+~\/\.tmux\.conf\s+\|\s+sh\s+-s\s+_split_window\s+((?:\\\\\")?|\"?|'?)#\{b:pane_tty\}\3)(.*?)\2/split-window\4/g -# ; -# s/\bsplit-window\b([^;}\n]*?)(?:\s+-c\s+((?:\\\\\")?|\"?|'?)#\{pane_current_path\}\2)/split-window\1/g" \ -# "$cfg" -# # 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 +# if ! _is_disabled "$tmux_conf_new_window_retain_current_path"; then # perl -p -i -e " -# s/\bnew-window\b(?!\s+(?:-|}))/{$&}/g if /\bdisplay-menu\b/ -# ; -# s/\bnew-window\b/new-window -c '#\{pane_current_path\}'/g" \ +# 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} +# if ! _is_disabled "$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+#\{b:pane_tty\}([^\n\1]*)(\s+-c\s+((?:\\\\\")?|\"?|'?)#\{pane_current_path\}\4)([^\n\1]*)\1/run-shell \1cut -c3- ~\/.tmux.conf | sh -s _split_window #{pane_pid} #{b:pane_tty}\2\5\1/g +# ; +# s/\brun-shell\b(\s+((?:\\\\\")?|\"?|'?)cut\s+-c3-\s+~\/\.tmux\.conf\s+\|\s+sh\s+-s\s+_split_window\s+((?:\\\\\")?|\"?|'?)#\{b:pane_tty\}\3)(.*?)\2/split-window\4/g +# ; +# s/\bsplit-window\b([^;}\n]*?)(?:\s+-c\s+((?:\\\\\")?|\"?|'?)#\{pane_current_path\}\2)/split-window\1/g" \ +# "$cfg" +# fi +# +# if ! _is_disabled "$tmux_conf_new_window_retain_current_path"; then +# if _is_true "$tmux_conf_new_window_retain_current_path"; then +# perl -p -i -e " +# s/\bnew-window\b(?!\s+(?:-|}))/{$&}/g if /\bdisplay-menu\b/ +# ; +# s/\bnew-window\b/new-window -c '#\{pane_current_path\}'/g" \ +# "$cfg" +# fi +# fi +# # perl -p -i -e " # s/\bsplit-window\b((?:(?:[ \t]+-[bdfhIvP])|(?:[ \t]+-[celtF][ \t]+(?!\bssh\b)[^\s]+))*)?(?:\s+(\bssh\b))((?:(?:[ \t]+-[bdfhIvP])|(?:[ \t]+-[celtF][ \t]+(?!\bssh\b)[^\s]+))*)?/run-shell 'cut -c3- ~\/\.tmux\.conf | sh -s _split_window_ssh #\{pane_pid\} #\{b:pane_tty\}\1'/g if /\bsplit-window\b((?:(?:[ \t]+-[bdfhIvP])|(?:[ \t]+-[celtF][ \t]+(?!ssh)[^\s]+))*)?(?:\s+(ssh))((?:(?:[ \t]+-[bdfhIvP])|(?:[ \t]+-[celtF][ \t]+(?!ssh)[^\s]+))*)?/"\ # "$cfg" # -# tmux_conf_new_pane_retain_current_path=${tmux_conf_new_pane_retain_current_path:-true} # tmux_conf_new_pane_reconnect_ssh=${tmux_conf_new_pane_reconnect_ssh:-false} -# if _is_enabled "$tmux_conf_new_pane_reconnect_ssh"; then +# if ! _is_disabled "$tmux_conf_new_pane_reconnect_ssh" && _is_true "$tmux_conf_new_pane_reconnect_ssh"; then # perl -p -i -e "s/\bsplit-window\b([^;}\n\"]*)/run-shell 'cut -c3- ~\/\.tmux\.conf | sh -s _split_window #\{pane_pid\} #\{b:pane_tty\}\1'/g" "$cfg" # fi # -# if _is_enabled "$tmux_conf_new_pane_retain_current_path"; then +# if ! _is_disabled "$tmux_conf_new_pane_retain_current_path" && _is_true "$tmux_conf_new_pane_retain_current_path"; then # perl -p -i -e " # s/\bsplit-window\b(?!\s+(?:-|}))/{$&}/g if /\bdisplay-menu\b/ # ; @@ -788,7 +804,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # fi # # tmux_conf_new_session_prompt=${tmux_conf_new_session_prompt:-false} -# if _is_enabled "$tmux_conf_new_session_prompt"; then +# if ! _is_disabled "$tmux_conf_new_session_prompt" && _is_true "$tmux_conf_new_session_prompt"; then # perl -p -i \ # -e "s/(? \/dev\/clipboard' # # if [ -n "$command" ]; then -# if _is_enabled "$tmux_conf_copy_to_os_clipboard"; then +# if ! _is_disabled "$tmux_conf_copy_to_os_clipboard" && _is_true "$tmux_conf_copy_to_os_clipboard"; then # perl -p -i -e "s/(?!.*?$command)\bcopy-(?:selection|pipe)(-and-cancel)?\b/copy-pipe\1 '$command'/g" "$cfg" # else # if [ $_tmux_version -ge 320 ]; then @@ -863,7 +879,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # tmux_conf_theme_focused_pane_bg=${tmux_conf_theme_focused_pane_bg:-$tmux_conf_theme_colour_2} # # window_style="fg=$tmux_conf_theme_window_fg,bg=$tmux_conf_theme_window_bg" -# if _is_enabled "$tmux_conf_theme_highlight_focused_pane"; then +# if _is_true "$tmux_conf_theme_highlight_focused_pane"; then # window_active_style="fg=$tmux_conf_theme_focused_pane_fg,bg=$tmux_conf_theme_focused_pane_bg" # else # window_active_style="default" @@ -1372,7 +1388,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # # TMUX_PLUGIN_MANAGER_PATH=${TMUX_PLUGIN_MANAGER_PATH:-~/.tmux/plugins} # if [ -z "$(tmux show -gv '@plugin')" ] && [ -z "$(tmux show -gv '@tpm_plugins')" ]; then -# if _is_enabled "$tmux_conf_uninstall_plugins_on_reload" && [ -d "$TMUX_PLUGIN_MANAGER_PATH/tpm" ]; then +# if _is_true "$tmux_conf_uninstall_plugins_on_reload" && [ -d "$TMUX_PLUGIN_MANAGER_PATH/tpm" ]; then # tmux display 'Uninstalling tpm and plugins...' # rm -rf "$TMUX_PLUGIN_MANAGER_PATH" # tmux display 'Done uninstalling tpm and plugins...' @@ -1383,7 +1399,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # install_tpm=true # tmux display 'Installing tpm and plugins...' # git clone --depth 1 https://github.com/tmux-plugins/tpm "$TMUX_PLUGIN_MANAGER_PATH/tpm" -# elif { [ -z "$window_active" ] && _is_enabled "$tmux_conf_update_plugins_on_launch"; } || { [ -n "$window_active" ] && _is_enabled "$tmux_conf_update_plugins_on_reload"; }; then +# elif { [ -z "$window_active" ] && _is_true "$tmux_conf_update_plugins_on_launch"; } || { [ -n "$window_active" ] && _is_true "$tmux_conf_update_plugins_on_reload"; }; then # update_tpm=true # tmux display 'Updating tpm and plugins...' # (cd "$TMUX_PLUGIN_MANAGER_PATH/tpm" && git fetch -q -p && git checkout -q master && git reset -q --hard origin/master) diff --git a/.tmux.conf.local b/.tmux.conf.local index 45725ae..fb77d04 100644 --- a/.tmux.conf.local +++ b/.tmux.conf.local @@ -20,21 +20,25 @@ # new window retains current path, possible values are: # - true # - false (default) +# - disabled (do not modify new-window bindings) tmux_conf_new_window_retain_current_path=false # new pane retains current path, possible values are: # - true (default) # - false +# - disabled (do not modify split-window bindings) tmux_conf_new_pane_retain_current_path=true -# new pane tries to reconnect ssh sessions (experimental), possible values are: +# new pane tries to reconnect ssh sessions, possible values are: # - true # - false (default) +# - disabled (do not modify split-window bindings) tmux_conf_new_pane_reconnect_ssh=false # prompt for session name when creating a new session, possible values are: # - true # - false (default) +# - disabled (do not modify new-session bindings) tmux_conf_new_session_prompt=false @@ -323,6 +327,7 @@ tmux_conf_theme_clock_style="24" # in copy mode, copying selection also copies to the OS clipboard # - true # - false (default) +# - disabled # on macOS, this requires installing reattach-to-user-namespace, see README.md # on Linux, this requires xsel or xclip tmux_conf_copy_to_os_clipboard=false