set tmux title in shell
change window title dynamically in tmux
according to this thread, i set my tmux windows title to the dir name of $PWD, thus i can tell the dirname of each windows :
export PS1=$'\ek${PWD##*/}\e\\\\\${USER}@${HOSTNAME} $ '
everything went well, until I exit tmux :
turn out if you’re out of tmux , there’s nothing can absorb the \033k…\033\ escape sequences, so it’s printed out
usually you don’t exit tmux ,but it seems really weird and imperfect for a normal shell.
luckily i found the magical two cursor command : sc (save_cursor) and rc (restore_cursor)
you can use it to wrap you ‘tmux shell command ‘:
export PS1=$'$(tput sc)\ek${PWD##*/}\e\\\\\$(tput rc)$(tput el)${USER}@${HOSTNAME} $ '
now the shell prompt is the same inside and outside tmux .
a colored prompt (tested in bash):
export PS1=$'$(tput sc)\ek${PWD##*/}\e\\\\\$(tput rc)$(tput el)[\[\e[0;32m\]\u@\h\[\e[1;34m\]\w\[\e[0m\]]\$ '