From fdc3b163a4ddfc02d488818c4b871b9a1cf73151 Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Fri, 29 May 2020 13:44:01 +0200 Subject: [PATCH 1/6] Allow disabling one or more bindings --- README.md | 11 ++++++++ pain_control.tmux | 64 +++++++++++++++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 07e0410..918652e 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,17 @@ Example: set-option -g @pane_resize "10" +To disable certain keys from being mapped by this plugin you can set +`@disabled_keys` to a comma-separated list of keys. It is empty by default, ie. +all keys will be mapped. + +Examples: + + # Disable | mapping + set-options -g @disabled_keys "|" + # Disable mapping of H, J, K and L + set-options -g @disabled_keys "H,J,K,L" + ### Other plugins You might also find these useful: diff --git a/pain_control.tmux b/pain_control.tmux index fd48409..54dce3c 100755 --- a/pain_control.tmux +++ b/pain_control.tmux @@ -15,41 +15,63 @@ get_tmux_option() { fi } +bind_key() { + local disabled_keys + local dis_key + local key + + key="$1" + + disabled_keys=$(get_tmux_option "@disabled_keys" "") + # comma-separated list to array + IFS=',' read -r -a disabled_keys <<< "$disabled_keys" + + for dis_key in "${disabled_keys[@]}" + do + if [[ "$dis_key" == "$key" ]] + then + # The user disabled the mapping of this key + return + fi + done + bind_key "$@" +} + pane_navigation_bindings() { - tmux bind-key h select-pane -L - tmux bind-key C-h select-pane -L - tmux bind-key j select-pane -D - tmux bind-key C-j select-pane -D - tmux bind-key k select-pane -U - tmux bind-key C-k select-pane -U - tmux bind-key l select-pane -R - tmux bind-key C-l select-pane -R + bind_key h select-pane -L + bind_key C-h select-pane -L + bind_key j select-pane -D + bind_key C-j select-pane -D + bind_key k select-pane -U + bind_key C-k select-pane -U + bind_key l select-pane -R + bind_key C-l select-pane -R } window_move_bindings() { - tmux bind-key -r "<" swap-window -d -t -1 - tmux bind-key -r ">" swap-window -d -t +1 + bind_key -r "<" swap-window -d -t -1 + bind_key -r ">" swap-window -d -t +1 } pane_resizing_bindings() { local pane_resize=$(get_tmux_option "@pane_resize" "$default_pane_resize") - tmux bind-key -r H resize-pane -L "$pane_resize" - tmux bind-key -r J resize-pane -D "$pane_resize" - tmux bind-key -r K resize-pane -U "$pane_resize" - tmux bind-key -r L resize-pane -R "$pane_resize" + bind_key -r H resize-pane -L "$pane_resize" + bind_key -r J resize-pane -D "$pane_resize" + bind_key -r K resize-pane -U "$pane_resize" + bind_key -r L resize-pane -R "$pane_resize" } pane_split_bindings() { - tmux bind-key "|" split-window -h -c "#{pane_current_path}" - tmux bind-key "\\" split-window -fh -c "#{pane_current_path}" - tmux bind-key "-" split-window -v -c "#{pane_current_path}" - tmux bind-key "_" split-window -fv -c "#{pane_current_path}" - tmux bind-key "%" split-window -h -c "#{pane_current_path}" - tmux bind-key '"' split-window -v -c "#{pane_current_path}" + bind_key "|" split-window -h -c "#{pane_current_path}" + bind_key "\\" split-window -fh -c "#{pane_current_path}" + bind_key "-" split-window -v -c "#{pane_current_path}" + bind_key "_" split-window -fv -c "#{pane_current_path}" + bind_key "%" split-window -h -c "#{pane_current_path}" + bind_key '"' split-window -v -c "#{pane_current_path}" } improve_new_window_binding() { - tmux bind-key "c" new-window -c "#{pane_current_path}" + bind_key "c" new-window -c "#{pane_current_path}" } main() { From c3c39fc7a1e6f87adcd21e6979d7e99909e3be4b Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Fri, 29 May 2020 13:57:05 +0200 Subject: [PATCH 2/6] Retab --- pain_control.tmux | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pain_control.tmux b/pain_control.tmux index 54dce3c..bc554d0 100755 --- a/pain_control.tmux +++ b/pain_control.tmux @@ -16,24 +16,24 @@ get_tmux_option() { } bind_key() { - local disabled_keys - local dis_key - local key + local disabled_keys + local dis_key + local key - key="$1" + key="$1" - disabled_keys=$(get_tmux_option "@disabled_keys" "") - # comma-separated list to array - IFS=',' read -r -a disabled_keys <<< "$disabled_keys" + disabled_keys=$(get_tmux_option "@disabled_keys" "") + # comma-separated list to array + IFS=',' read -r -a disabled_keys <<< "$disabled_keys" - for dis_key in "${disabled_keys[@]}" - do - if [[ "$dis_key" == "$key" ]] - then - # The user disabled the mapping of this key - return - fi - done + for dis_key in "${disabled_keys[@]}" + do + if [[ "$dis_key" == "$key" ]] + then + # The user disabled the mapping of this key + return + fi + done bind_key "$@" } From 6744880fca673fca632f2ae6655f75b0be238700 Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Fri, 29 May 2020 13:59:19 +0200 Subject: [PATCH 3/6] Re-retab --- pain_control.tmux | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pain_control.tmux b/pain_control.tmux index bc554d0..a7940a7 100755 --- a/pain_control.tmux +++ b/pain_control.tmux @@ -28,11 +28,11 @@ bind_key() { for dis_key in "${disabled_keys[@]}" do - if [[ "$dis_key" == "$key" ]] - then - # The user disabled the mapping of this key - return - fi + if [[ "$dis_key" == "$key" ]] + then + # The user disabled the mapping of this key + return + fi done bind_key "$@" } From fc5283ba76a6e3b78a1799537837815b108a0f08 Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Sat, 30 May 2020 10:57:08 +0200 Subject: [PATCH 4/6] Read values without messing with IFS --- pain_control.tmux | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pain_control.tmux b/pain_control.tmux index a7940a7..44bfe49 100755 --- a/pain_control.tmux +++ b/pain_control.tmux @@ -24,7 +24,7 @@ bind_key() { disabled_keys=$(get_tmux_option "@disabled_keys" "") # comma-separated list to array - IFS=',' read -r -a disabled_keys <<< "$disabled_keys" + read -r -a disabled_keys <<< "${disabled_keys//,/ }" for dis_key in "${disabled_keys[@]}" do From 6db97bf5f70c479cfd049e980bcce88e58a66dea Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Sat, 30 May 2020 10:57:33 +0200 Subject: [PATCH 5/6] Remove infinite loop --- pain_control.tmux | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pain_control.tmux b/pain_control.tmux index 44bfe49..c963212 100755 --- a/pain_control.tmux +++ b/pain_control.tmux @@ -34,7 +34,7 @@ bind_key() { return fi done - bind_key "$@" + tmux bind-key "$@" } pane_navigation_bindings() { From 27e48aeacda31aad7209604b71a69f20c91adfa6 Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Sat, 30 May 2020 10:58:28 +0200 Subject: [PATCH 6/6] Sort --- pain_control.tmux | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pain_control.tmux b/pain_control.tmux index c963212..4fc1200 100755 --- a/pain_control.tmux +++ b/pain_control.tmux @@ -16,8 +16,8 @@ get_tmux_option() { } bind_key() { - local disabled_keys local dis_key + local disabled_keys local key key="$1"