6

Is it possible to disable the behavior which causes selecting a pane on opposite side of a tmux window if there are no more panes left in a direction select-pane command was originally triggered at?

If not, is there a way how to determine if any other panes exist in a specific direction?

If a tmux window doesn't have a (v)split active window and a select-pane command is triggered, an error message is thrown - this is expected behavior.

Thank you for response

  • Sorry for brining up such an old question, but did you find a way do disable the auto-cycling behavior?? – Edvin Nov 14 '17 at 14:43
  • Nope. I guess it wasn't causing me that much of pain so I wasn't determined enough. You would probably need to fork the project and edit the source. – user2694295 Nov 14 '17 at 16:30
  • Fair enough. As you said, only mildly annoying. – Edvin Nov 15 '17 at 12:09
7

Add this to your ~/.tmux.conf:

set-option -g default-shell /bin/bash
unbind Up     
unbind Down   
unbind Right   
unbind Left  
bind Up run-shell "if [ $(tmux display-message -p '#{pane_at_top}') -ne 1 ]; then tmux select-pane -U; fi"
bind Down run-shell "if [ $(tmux display-message -p '#{pane_at_bottom}') -ne 1 ] ; then tmux select-pane -D; fi"
bind Right run-shell "if [ $(tmux display-message -p '#{pane_at_right}') -ne 1 ]; then tmux select-pane -R; fi"
bind Left run-shell "if [ $(tmux display-message -p '#{pane_at_left}') -ne 1 ]; then tmux select-pane -L; fi"

Basically, this should run with tmux versions 2.6 + (after which they added the pane_at_top, pane_at_bottom, pane_at_left, pane_at_right environment variables. For tmux < v2.6, I'm not entirely sure how you could implement this.

Further more, if you want to launch a custom-shell, do it through set-option -g default-command fish (or zsh or csh or whatever). As an alternative, if you want to use a non-bash shell as your tmux default shell, set it as such (set-option -g default-shell) and then you can code out the logic above in the shell script of your choice. However, (as was in my case) using certain shells doesn't give you the convenience of one-liner if commands (or it might just be I don't know enough about certain shells, or maybe multiple lines do work in run-shell.

Source: github Issues thread that I started

| improve this answer | |
2

Thanks to Gilgamesh Skytrooper for posting the issue on github. Here's a simple version that can work with multiple sessions and doesn't invoke a shell subprocess.

bind -n M-a if -F '#{pane_at_left}'   '' 'select-pane -L'
bind -n M-d if -F '#{pane_at_right}'  '' 'select-pane -R'
bind -n M-w if -F '#{pane_at_top}'    '' 'select-pane -U'
bind -n M-s if -F '#{pane_at_bottom}' '' 'select-pane -D'

Remove -n if you want to hit the prefix (C-b) first, and change the bindings M-[awds] to your liking.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.