12

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.

Prabhu M
  • 483
  • 2
  • 7
  • 9
  • i figured out a workaround. while starting echo "tmux new -s whirr" > whirrtmux.sh ./whirrtmux.sh Since Iterm always display the current command that running, it will display "./whirrtmux.sh" in the tab title. if anyone has a better way to do this... please let me know – Prabhu M Aug 28 '12 at 22:41

4 Answers4

17

add these to your ~/.tmux.conf:

set-option -g set-titles on
set-option -g set-titles-string "#{session_name} - #{host}"
Dryice Liu
  • 311
  • 2
  • 4
  • btw, need to uncomment DISABLE_AUTO_TITLE="true" in ~/.zshrc if using zsh. – Yu-Lin Chen Apr 18 '18 at 06:51
  • Worked perfectly for me, I'm using zsh and did not need to set the config mentioned by Yu-Lin above – jlhasson Apr 30 '22 at 20:49
  • It adds a "(tmux)" string after the session name. Was wondering if that could be removed? That aside, it worked great. – Kev May 18 '22 at 07:54
2

My workflow is usually centered around panes, and I don't use tmux, so I used a slight variation of @mislav answer:

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

precmd_functions=($precmd_functions set_terminal_tab_title)

I threw that into my zshrc; then, in each pane, I export TABTITLE='FOO'. That way, when I switch panes, I get the title I want on the tab.

verboze
  • 419
  • 1
  • 7
  • 10
1

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.

mislav
  • 14,919
  • 8
  • 47
  • 63
1

Bash Version to display Hello World as a title:

echo -ne "\033]0; Hello World \007"

And if you want title refreshed each time bash print your prompt:

export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}: ${PWD/#$HOME/~}\007"'

Found it on http://hints.macworld.com/article.php?story=20031015173932306

Hadrien
  • 1,479
  • 2
  • 14
  • 18