Rename Iterm2 tab from within tmux
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!
Solution 1:
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
Solution 2:
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
}
Solution 3:
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 ->
tmux ->
Dashboard -> select a window ->
Press return to rename (just like in Finder!)