Ubuntu – Is it possible to apply different colors to terminal tabs in GNOME based on the opened directory

colorsgnome-terminal

Is it possible to apply different colors to terminal tabs in GNOME based on the opened directory?

e.g.

having red background for tab when it is open in:

/path/one/*

and the green one when tab is in:

/path/two/*

Best Answer

Yes it is, if you're willing to subvert the cd builtin.

Here (from my ~/.bashrc) is how I put my Username, Host and Current directory in my window title:

# from the "xttitle(1)" man page - put info in window title
update_title()
{
    [[ $TERM = xterm ]] || [[ $TERM = xterm-color ]]  && xttitle "[$$] ${USER}@${HOSTNAME}:$PWD"
}

cd()
{
    [[ -z "$*" ]] && builtin cd $HOME
    [[ -n "$*" ]] && builtin cd "$*"
    update_title
}

Replace the update_title function with one of your own to look at the current directory and Do the Right Thing.