Rename Iterm2 tab from within tmux

17

1

I can use the following function to rename a iterm2 tab and that works great.

function rename_tab {
    echo -ne "\033]0;"$@"\007"
}

However, if I run this function while in a tmux session, then nothing happens.

Any idea how to make this work while in tmux? Thanks!

chevett

Posted 2014-01-15T18:28:01.607

Reputation: 308

Answers

18

You can use the tmux option set-titles

In my .tmux.conf I have the following line:

set-option -g set-titles on

You will need to restart the tmux server (kill existing sessions) or re-source the file before the change in your config takes effect. You can also run this for an existing session with <prefix>:set-option set-titles on

asfallows

Posted 2014-01-15T18:28:01.607

Reputation: 861

You can reload the tmux config pretty easily with tmux source-file ~/.tmux.conf. Source - http://blog.sanctum.geek.nz/reloading-tmux-config/

– studgeek – 2016-04-09T04:50:03.260

1This does not work when using the tmux integration (e.g. running with tmux -CC ) – Bittenus – 2016-10-28T10:59:16.077

Any solution for using control mode (aka tmux -CC)? May be a bug in tmux? – steshaw – 2018-04-25T01:57:15.467

2Awesome! Thanks! <prefix>:set-option set-titles-string tab-name-here did exactly what I wanted. – chevett – 2014-01-15T18:36:34.640

3set-option -g set-titles on set-option -g set-titles-string '#S' – chevett – 2014-01-15T18:48:56.210

4

I could not get the set-titles to work when using the tmux integration in iTerm2 (running with tmux -CC)

Instead this works just fine

function tabname {
  if [ -z $TMUX ] ; then
    printf "\e]1;$@\a"
  else
   tmux rename-window "$@"
  fi
}

Bittenus

Posted 2014-01-15T18:28:01.607

Reputation: 817

Did you put this in your .bashrc/.zshrc file? Or could we place this into .tmux.conf? – danyim – 2017-04-16T22:30:28.290

I put it in .bashrc – Bittenus – 2017-04-18T05:09:35.773

0

This answer is not a direct reply to the question, sorry about that. It is instead how to do this from iTerm2 without a command line equivalent.

iTerm Menu Bar -> Shell ->

Shell

tmux ->

tmux

Dashboard -> select a window ->

Dashboard

Press return to rename (just like in Finder!) Press enter to rename

Graham P Heath

Posted 2014-01-15T18:28:01.607

Reputation: 146