As of tmux 2.6, tmux now allows per-pane titles. They can be enabled via tmux set -g pane-border-status top
. This is very convenient when running 10+ panes per window. I also set my title format as follows, to allow me to rename them:
set -g pane-border-format "#{pane_index} #{pane_title}"
# rename prompt
bind . command-prompt -p "(rename-pane)" -I "#T" "select-pane -T '%%'"
The only thing I don't like is the fallback default, which defaults to hostname of the machine. I would prefer the following instead:
- if
pane_title
is set by the user, use that (#{pane_title}
) - otherwise, use current working directory (
#{pane_current_path}
)
Either one by itself is straight-forward:
tmux set -g pane-border-format "#{pane_index} #{pane_title}"
tmux set -g pane-border-format "#{pane_index} #{pane_current_path}"
The formatting section of tmux (https://github.com/tmux/tmux/wiki/Formats) shows that I can use a ternary conditional check to achieve the kind of fallback I want, but I'm having trouble getting it working in all cases due to the fact that pane_index
, when unset, seems to default to (my guess) whatever hostname
command returned at the time the pane was spawned. Here is what I currently have:
tmux set -g pane-border-format "#{pane_index} #{?#{!=:#{pane_title},$(hostname)},#{pane_title},#{pane_current_path}}"
This works for panes that have been explicitly renamed by the user, and also for panes that were spawned with the same hostname. Unfortunately, the hostname on my work machine changes with IP, so the above command seems too fragile. To make things worse, for some reason it only works when ran directly from a pane rather than when put into tmux config (without the tmux prefix, of course). Is there a better way to determine if pane_title is unset?