Linux – tmux select-pane -LDUR command – disable auto-cycling behavior

commandlinuxpanelterminaltmux

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

Best Answer

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

Related Question