25

A problem I have with Tmux - in the .tmux.conf file I have told him not to rename windows after I set their names but it seems that it is not "respecting my authority" :).

My system:

  • OSX El Capitan
  • Tmux 2.1 (installed via Brew)
  • Zshell

Here is my ~/.tmux.conf content (I apologise it's quite long):

# set correct term
set -g default-terminal screen-256color

# set prefix key to ctrl+a
#unbind C-b
set -g prefix C-a 

# reload config without killing server
bind R source-file /users/edchigliak/.tmux.conf 

# enable wm window titles
set -g set-titles on

# disable auto renaming
set -g automatic-rename off

# border colour
set -g pane-border-fg blue
set -g pane-border-bg default
set -g pane-active-border-fg blue
set -g pane-active-border-bg default

# wm window title string (uses statusbar variables)
set -g set-titles-string "tmux:#I [ #W ]"

# initialize sessions
bind S source-file ~/.tmux.conf 
bind I source-file ~/.tmux.conf

# environment
set -g update-environment "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"

# statusbar --------------------------------------------------------------
set -g window-status-format "#I:#W"
set -g window-status-current-format "#I:#W"

set -g status-keys vi
bind-key -t vi-edit Up history-up
bind-key -t vi-edit Down history-down

set -g status-interval 1
set -g status-justify centre # center align window list

# default statusbar colors
# wm window title string (uses statusbar variables)
set -g set-titles-string "tmux:#I [ #W ]"

# initialize sessions
bind S source-file ~/.tmux.conf 
bind I source-file ~/.tmux.conf

# environment
set -g update-environment "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"

# statusbar --------------------------------------------------------------
set -g window-status-format "#I:#W"
set -g window-status-current-format "#I:#W"

set -g status-keys vi
bind-key -t vi-edit Up history-up
bind-key -t vi-edit Down history-down

set -g status-interval 1
set -g status-justify centre # center align window list

# default statusbar colors
set -g status-fg white
set -g status-bg default

# default window title colors
set-window-option -g window-status-fg black
set-window-option -g window-status-bg default
set-window-option -g window-status-attr dim

# active window title colors
set-window-option -g window-status-current-fg white
set-window-option -g window-status-current-bg default
set-window-option -g window-status-current-attr dim

# command/message line colors
set -g message-fg white
set -g message-bg black
set -g message-attr bright

# Statusbar starting in X or not
# if '[ -n "$DISPLAY" ]' 'source-file ~/.tmux/inx'
# if '[ -z "$DISPLAY" ]' 'source-file ~/.tmux/xless'

If I try:

~ > echo $TERM

I get the correct:

screen-256color

which makes me believe that it is sourcing the right .conf file. Also, control key bindings DO change from Ctrl+b to Ctrl+a. However, window names that I change via Ctrl + a and then ,simply will not stay put.

Any ideas what is going on? Thanks!

Alexander Starbuck
  • 1,139
  • 4
  • 18
  • 31
  • It is possible that it is `zsh`, which is changing your window titles, especially if the titles only change when you start a program or the shell prompt is issued. Any chance you could link your shell configuration? Otherwise look for `print` or `echo` statements with strings that start with `\e]2;` or `\033]2;` and end in `\a` or `\e\\` or `\033\\`. – Adaephon Jul 29 '16 at 12:27
  • 1
    You were right! ZSH was messing things up. I had to uncomment this line `export DISABLE_AUTO_TITLE="true"` in my `.zshrc`. Please create an answer to my question and I'll gladly accept it. – Alexander Starbuck Jul 29 '16 at 12:53

3 Answers3

51

A likely cause for this is, that zsh is configured to update the window title when starting a program or issuing the prompt. This is done by using the terminal escape sequence \ek<TEXT>\e\\ where <TEXT> is the window title.

To prevent this you have two options:

  • Disallow window renaming in the tmux configuration.

    Just add

    set allow-rename off
    

    to your ~/.tmux.conf. This prevents any program from changing the window title by using the aforementioned terminal escape sequence.

  • Track down the setting in your zsh configuration and disable it.

    If you are using oh-my-zsh, it should be enough to set

    DISABLE_AUTO_TITLE="true"
    

    in your ~/.zshrc (or just uncomment it, if you are using the default .zshrc template from oh-my-zsh).

    If you use your own configuration or some other configuration framework, you should be able to track it down by searching for \ek (do not forget to quote the backslash if your search tool requires it).

Adaephon
  • 16,929
  • 1
  • 54
  • 71
  • 1
    ah, thankyou thankyou thankyou! This was KILLING me :) :) :) – vitiral Apr 24 '18 at 16:10
  • 4
    please remember reload config file with `tmux source-file ~/.tmux.conf` – LoranceChen Jul 04 '18 at 08:33
  • I'd like to emphasize this setting is __per window__. If you create multiple windows from a script, you have to put `set allow-rename off` after every window creation command as that will be the active window at that moment. – karatedog Dec 17 '21 at 11:23
11

For people running bash and landing on this result, the thing that sets the title is the PROMPT_COMMAND environmental variable, which some shared system annoyingly set. You can do that with unset PROMPT_COMMAND (e.g. in your .bashrc)

Davide
  • 17,098
  • 11
  • 52
  • 68
  • Likewise, you might have a .vimrc setting causing the rename. Perhaps previously you followed this advice https://stackoverflow.com/questions/15123477/tmux-tabs-with-name-of-file-open-in-vim/15124717#15124717. – user68873 Jul 17 '19 at 17:31
  • And not only the .vimrc, but other vim plugin like Nvim-r (https://github.com/jalvesaq/Nvim-R/)! If you still uses the tmux option as I do, the file : `Nvim-R/R/tmux_split.vim` rename the windows each you start R – Simon C. Feb 07 '23 at 16:54
4

For this to work for me I had to add this line to ~/.tmux.conf

set-window-option -g allow-rename off
Drew LeSueur
  • 19,185
  • 29
  • 89
  • 106