Customize titles of your terminal window

less than 1 minute read

If you are like me, you use many many tabs in your command line terminal. By the way, iTerm2 is a very nice improvement over the vanilla OS X Terminal app.

To recognize tabs, I like to display the name of the current directory and add the directory it is contained in if more space are left. Open your .bash_profile or .profile file and add the following

function local_dir_and_within {

__LAST="${PWD##*/}"

__IN="${PWD%/*}"

__IN="${__IN/#$HOME/~}"

TITLE_TAB="$__LAST in $__IN"

echo -n $TITLE_TAB

}

export PROMPT_COMMAND='echo -ne "\033]0;$(local_dir_and_within)\007"'

Your tab title will now look like hibernate-search in ~/code.

Comments