pdoherty926
pdoherty926

Reputation: 10349

Prevent tmux's pane_title from being updated

I'm trying to write a script which will programmatically set a tmux pane's title. I've got it mostly working by using the following:

# tmux.conf
set -g pane-border-format "#{pane_index}:#{pane_title}"
# script
# ...
tmux select-pane -t foo:0.0 -T "this will be shortlived"

However, as soon as I do anything in that pane, the custom title is unset. I've looked through tmux's source, but have not been able to find anything obvious answers. (The value appears to be a fragment of my $PS1.)

So, how is is pane_title set and is there any way for me to prevent it from overriding my custom title? (I'm pretty sure you can use a shell function to populate value's within the pane-border-format string template, but this doesn't really work if the values are set dynamically via a script.)

Upvotes: 2

Views: 826

Answers (1)

user11274868
user11274868

Reputation:

The intent of pane title is for applications inside tmux to update it, there is no way to prevent this happening other than configuring every application not to do it, or modifying tmux itself. In this case, it is your shell changing it. You can check your shell profiles and the system shell profiles for the OSC title setting sequence (\033]2; or \033]0; or \e[2; or \e[0;), but other programs will still feel free to change it.

If you want a custom pane title that can't be modified by applications, the best bet is to use a user option. If you have tmux 3.0a or later you can set it on the pane in your script:

[ -n "$TMUX" ] && tmux set -p @mytitle "foo"

Then use it in pane-border-format:

set -g pane-border-format "#{@mytitle}"

If you have an older tmux there are no pane options but it is possible by using an option named with the pane ID, something like:

if [ -n "$TMUX" ]; then
    I=$(tmux display -p '#{pane_id}')
    tmux set -w "@mytitle_$I" "foo"
fi

Then:

set -g pane-border-format '#(tmux show -wv "@mytitle_#{pane_id}")'

Upvotes: 5

Related Questions