Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set iterm2 tab title to that of a running tmux session name?

i know tmux display-message -p '#S' will display the current tmux session name, but i donno how to set the current tmux session name to the iterm2 tab title?

This would really help me to distinguish the various tmux sessions that i am running concurrently and jump to the correct tab rightaway.

like image 755
Prabhu M Avatar asked Aug 18 '12 12:08

Prabhu M


2 Answers

add these to your ~/.tmux.conf:

set-option -g set-titles on
set-option -g set-titles-string "#{session_name} - #{host}"
like image 79
Dryice Liu Avatar answered Oct 29 '22 22:10

Dryice Liu


Stick this in your ~/.zshrc:

set_terminal_tab_title() {
  print -Pn "\e]1;$1:q\a"
}

indicate_tmux_session_in_terminal() {
  set_terminal_tab_title "$(tmux display-message -p '#S')"
}

precmd_functions=($precmd_functions indicate_tmux_session_in_terminal)

precmd_functions is an array that in zsh contains the list of functions to call prior to showing the prompt. If you add your own function to the list, it will get called whenever the prompt is shown, making it a good place to periodically update the terminal tab title.

like image 21
mislav Avatar answered Oct 29 '22 23:10

mislav