Tmux and ZSH custom prompt : bug with window name

44

17

I have customized my ZSH prompt with oh-my-zsh to make it more readable and add information about git if I'm in a repository.

Example :
bob@inf [~/docs] %
bob@inf [~/src/nicest] master % (in a git repository)

It works well but I have some bugs with tmux and the window name. It still display non sense value and I cannot disable it with automatic-rename off (it just do not work, the window name change after each command), for the first example tmux use ~/docs for the window name.

I'm not sure how I can fix it, I would like to keep my zsh prompt as it is, if can make change but would like to understand where is the problem ?

Another solution may be to redefine command settile (from this answer) but I'm not sure how to do it the right way.

Adrien Coquio

Posted 2011-07-04T09:55:15.067

Reputation: 543

Answers

77

I took a peek at oh-my-zsh and found a likely suspect.

When the value of the TERM environment variable starts with screen (which it should under both screen and tmux), it uses a screen terminal control sequence to set the window’s name to

  • (just before displaying a shell prompt)
    the left-most portion of the “tilde compressed” path of the current working directory (.. followed by the last 13 characters or the entire path if it less than 15 characters) and
  • (just before starting a command)
    the first “word” of about-to-be-run command (not counting ssh, sudo, and a few others).

It sounds like it is working this way for you (you said that your window named changed to ~/docs when you were in that directory). If you want to disable this automatic renaming, you can can disable it completely by setting the DISABLE_AUTO_TITLE shell parameter to true in your .zshrc:

DISABLE_AUTO_TITLE=true

If you just set this in an interactive shell, you will end up with an empty string for the current window’s name, but oh-my-zsh will stop updating the window before each prompt and command in that shell instance (it needs to be in your .zshrc to affect all new shell instances).

Chris Johnsen

Posted 2011-07-04T09:55:15.067

Reputation: 31 786

Thank you thank you thank you thank you thank you thank you – Jezen Thomas – 2014-09-25T10:16:42.483

where is a .zshrc file for all users? – andilabs – 2015-01-16T09:02:46.163

4This is such a perfect answer. Accurate, informative, concise and to the point. Moreover, it provides a solution in addition to answering the original question ("understanding where is the problem").It's only sad that whoever took the time to ask didn't bother marking this as the answer. – dmondark – 2013-03-05T06:03:35.153

31

I know that the answer above gives you a solution, but another one is to simply add this option your the ~/.tmux.conf

set-option -g allow-rename off

albertogg

Posted 2011-07-04T09:55:15.067

Reputation: 411

This is a better solution since it only affects tmux. – Paul Oliver – 2014-11-15T04:32:15.320

Even with this setting, join-pane followed by break-pane resets the window name :( – djsadinoff – 2015-12-22T14:13:15.160

6

I met the same issue, which is tmux's window name was changed even by setting in .tmux.conf:

set-window-option -g automatic-rename off

Thanks Chris's answer. My tmux window name wasn't renamed automatically after I changed:

set -g default-terminal "screen-256color"

to:

set -g default-terminal "xterm-256color"

rwxrwxrwx

Posted 2011-07-04T09:55:15.067

Reputation: 821

0

If you want to disable the automatic-rename only for certain window then you can use:

 set -t [WINDOW_NUMBER] automatic-rename off

Disable the automatic-rename in specific window in another session:

 set -t [SESSION]:[WINDOW_NUMBER] automatic-rename off

Viktor Nonov

Posted 2011-07-04T09:55:15.067

Reputation: 343