There are two issues here.
One is how to detect if you're running inside gnome-terminal (or any other app using the same vte widget for the current terminal emulation). Assuming you're on a recent enough Ubuntu, the presence of the $VTE_VERSION
variable tells you this. You could edit your .bashrc
to contain something like
if [ -n "$VTE_VERSION" ]; then
# Gnome-terminal and other vte3-based emulators
color_prompt=yes
fi
The other issue is that for some reason Ubuntu's default .bashrc
tries to look for xterm-color
which is not really used nowadays. Either the standard xterm
(which supports colors anyways), or the more modern xterm-256color
are the popular choices, the default slowly moving towards the latter. (gnome-terminal changed its default from xterm
to xterm-256color
in 3.16, which is present in Ubuntu 15.10 beyond)
If you would like to move forward and already enjoy plenty of colors in several applications, I recommend that you already switch to TERM=xterm-256color
, which you could also do in the if-branch above.
Ubuntu's .bashrc
is obsolete for using xterm-color
. I much rather recommend modifying these bits in the script around whatever $TERM
you already have (xterm
) or would prefer to have (maybe xterm-256color
), rather than the other way around, modifying $TERM
to match .bashrc
's requirement.
tput colors
.