2

I'd like to have tmux "instantly" update the pane's title to match what is currently being executed in the terminal. For an instance:

  • If the pane contains the shell then its title should be bash.
  • If the pane contains vim being executed then its title should be vim.
  • If the pane contains nano being executed then its title should be nano.

However that's not the case and what happens is as follows:

If I have bash shell in the pane then I execute vim what happens is that the pane's title doesn't update until an event occurs (such as pressing a key or switching to another pane) or after a specific interval of time has passed and this interval is specified by:

set-option -g status-interval interval

Same thing happens when quitting vim, the title doesn't change unless an event happens or after the interval has passed.

What I want is that the pane's title updates instantly upon the change of the current command being executed (i.e. when I type vim in bash and press Enter then the title instantly changes to vim). However, as far as I know (and if that's wrong please do correct me) the interval specified by set-option -g status-interval interval can't be less than 1 second and even 1 second is still a noticeable delay in this case. So how can I force instant update for the pane's title?

The OS is Debian 12.
tmux version is tmux 3.3a.

4
  • What is the OS? What is the version of tmux? (tmux -V). Apr 15 at 3:21
  • @KamilMaciorowski OS is debian 12. tmux version is "tmux 3.3a"
    – pic810
    Apr 15 at 12:02
  • Please do not cross-post. For the record, the other copy is on Unix & Linux SE. Apr 15 at 22:25
  • 1
    The author or tmux addressed a similar problem here. When I'm writing this, that answer is accepted, but the solution that really helped the OP is in the comments. Apr 17 at 5:26

1 Answer 1

0

Instant updates based on the command are impossible in the automatic-rename mechanism that's being used here, because tmux itself does not know what is being executed and when. It is not told by the OS about what processes are being run several layers down the stack – it has to periodically scan the process list to detect any changes. Trying to approximate "instant" updates would lead to significant CPU usage.

To make the update instant, your interactive shell (or the program being run) has to explicitly tell tmux about the new command – or more specifically about the new title and/or the "window name" (shows up in the status bar).

  • For example, in Zsh you would have to set the window name from precmd(), and in Bash you would probably need to use trap DEBUG or the third-party "bash precmd" script.

    printf '\e]0;%s\e\\' "New terminal title"
    
    printf '\ek%s\e\\' "New window name"
    

    This SO post has a good example of how you could automate setting the pane title using 'trap DEBUG' in Bash. (It checks for screen* but the same mechanism is understood by practically all terminals including tmux.)

  • Since you're specifically asking about "pane title", which uses the general title/statusline mechanism found in other terminals (and not about the "window name", which is screen/tmux-specific): Many programs can update the terminal title on their own; for example, in Vim you just need to set title to enable this feature.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .