3

Something similar was asked here but I wasn't able to resolve the issue for me

tmux:

# use titles
set-option -g set-titles on
set-option -g set-titles-string '#T'

# add custom term
set -g default-terminal "tmux-256color"
set -as terminal-overrides ',xterm*:XT:sitm=\E[3m'

# always reattach to user namespace
set-option -g default-shell $SHELL
set-option -g default-command "reattach-to-user-namespace -l $(echo $SHELL)"

bash

  case "$TERM" in
    tmux*)
      printf '\033]2;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\033\'
      PROMPT_COMMAND="printf '\033]2;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\033\'"
      ;;
    xterm*)
      if [ $ITERM_SESSION_ID ]; then
        export PROMPT_COMMAND='echo -ne "\033];${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"; ': $PROMPT_COMMAND;
      fi
      ;;
  esac

Bash is keeping the title updated just fine, however in tmux I can't manage to get it to always keep the current title as well.

tmux (title isn't updated after changing dir)

enter image description here

non-tmux (title is updated after changing dir) enter image description here

Is there a way to reliably keep the tmux title in sync with what the bash title is?

patchrail
  • 141

1 Answers1

1

After a lot of back and forth and a few dozen tmux reloads/restarts, I finally found a solution that works exactly the way I want, in all terminal emulators I want (iTerm/Kitty/Terminal.app), with or without tmux

bashrc

case "$TERM" in
  tmux*)
    export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
    ;;
  xterm*)
    if [ $ITERM_SESSION_ID ]; then
      export PROMPT_COMMAND='echo -ne "\033];${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"; '
    else
      export PROMPT_COMMAND='echo -ne "\033]${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"; '
    fi
    ;;
esac

tmux

# use titles
set-option -g set-titles on
set-option -g set-titles-string "#T"
set-option -g automatic-rename on
patchrail
  • 141