Can I set a default title for a tmux window?

38

11

Right now the title defaults to reattach-to-user-namespace (OS X), which is pretty annoying. Is there an option I can put into my tmux.conf to get another default title?

If not, how would I make a key binding that creates a new window and then prompts me for a name?

js-coder

Posted 2013-03-13T19:17:02.333

Reputation: 543

What is the best way to put the window number in the name? – DanCat – 2018-02-08T18:19:51.257

See answer here http://superuser.com/questions/306028/tmux-and-zsh-custom-prompt-bug-with-window-name

– Fredrik Pihl – 2013-03-13T19:38:54.767

That's about disabling automatic renaming (which I already did), not about default names, right? – js-coder – 2013-03-13T19:46:11.710

I guess you're right, sorry! – Fredrik Pihl – 2013-03-13T19:46:50.883

I use set-option -g default-command "reattach-to-user-namespace -l zsh", and most of the time end up with a window named zsh, as desired. For unknown reasons, sometimes the name doesn't switch, and the window is called reattach-to-user-namespace. I still haven't noticed a pattern as to when/why this happens, but it seems like there might be a subtle bug, or something in my configuration. – Jim Stewart – 2013-11-05T02:28:14.367

Answers

43

There is no global default window name that is applied to all new windows; they default to (part of) the first “word” of the command (or the default shell if there is no command). Your windows are probably defaulting to reattach-to-user-namespace because you that is the first interesting bit of your default-command value.

It would be a bit round-about, but you could put your default command in a shell script and point your default-command to that script instead. With that configuration the default window name (for windows created without an explicit command) would be whatever you named the shell script.

Otherwise, there are several ways to manually name/rename a window:

  • At creation time with -n:

    new-window -n 'some name'
    

    You could re-bind c (the default key used to create a window) to incorporate a “default name” of your choosing:

    bind-key c new-window -n 'default name'
    
  • Rename an existing window:

    rename-window 'new name'
    

    There is also a default binding (Prefix ,) that will prompt you for a new name and rename the window.

  • Rename a window via an “escape sequence” sent to a pane’s tty:

    # E.g. in a shell:
    printf '\033kWINDOW_NAME\033\\'
    

Your “prompt me for a name for a new window” can be done like this (prompting before or after creating the window):

bind-key C command-prompt -p "Name of new window: " "new-window -n '%%'"

bind-key C new-window \; command-prompt -p "Name for this new window: " "rename-window '%%'"

Chris Johnsen

Posted 2013-03-13T19:17:02.333

Reputation: 31 786

2Wow, this is a really epic answer, thanks a lot! :) – js-coder – 2013-03-14T11:15:30.423

7I found a way to set a default title: set-option -g default-command "tmux rename-window base; reattach-to-user-namespace -l zsh" sets a default title of base. You might want to add this to your answer. :) – js-coder – 2013-03-24T21:07:06.337

your solution breaks tmux managers like tmuxinator. In that case, the tabs do not get renamed – SystematicFrank – 2013-11-13T10:27:04.393

4

tmux picks the first command as the window name.

Say you want "i" to be the default title, you can trick it like this.

set-option -g default-command "i > /dev/null 2>&1; reattach-to-user-namespace -l bash"

This is better than

set-option -g default-command "tmux rename-window i; reattach-to-user-namespace -l bash"

because if you create a pane after you manually set a window title, the title will be renamed back to "i" again.

David

Posted 2013-03-13T19:17:02.333

Reputation: 41

1

Not really an answer more than a hack:

I created a symlink with

sudo ln -s /usr/local/bin/reattach-to-user-namespace /usr/local/bin/pbash

And now it shows as pbash as the default title.

Marco Aurelio

Posted 2013-03-13T19:17:02.333

Reputation: 111

1

In addition to Chris' answer on setting the window title using new window -n 'somename', you can also provide an empty string '' as the name of a window. This way, I can use the default shortcut (prefix + c) and do not need to come up with a name for temporary windows, but can still rename them when neccessary:

bind-key c new-window -n ''

Ferdy

Posted 2013-03-13T19:17:02.333

Reputation: 11