tmux window name

Here’s how I got my tmux windows to be named ‘short hostname:working directory’.

Create a bash function in your $HOME/.bashrc.

settitle ()
    # only run this in tmux
    case "$TERM" in
            # get hostname without FQDN
            H=`hostname -s`
            # get current directory without the full path
            D=`basename $PWD`
            # set title of tmux/screen window
            printf "33k$H:$D33\\"

Then call settitle from your PS1 prompt variable:

PS1="...(settitle)\$ "

Here is my current prompt:

PS1="[\u@\h \W\$(git branch 2> /dev/null | grep -e '\* ' | sed 's/^..\(.*\)/{\1}/')]\$(settitle)\$ "