I'm configuring my prompt (PS1
) via .bashrc and found one issue with my current configuration: I am using a 256 color scheme. This is not compatible with the classical terminal (accessible via e.g. Ctrl+Alt+F2) but looks beautiful in graphical terminals such as gnome-terminal, terminator, etc.
So I have to change my prompt depending on the type of terminal. To do this, I need a condition for if
clause to test the type of terminal. Do you know how to do this?
the TERM
variable indicates the terminal type.
when running in an x-terminal, it is usually xterm
(but can also be xterm-color-256
as Dmitry has hinted in his answer).
the following code checks whether the value of $TERM starts with xterm
(and thus catches several cases):
case "$TERM" in
xterm*)
echo "running as an x-terminal"
;;
*)
echo "not running as an x-terminal"
;;
esac
echo $TERM
would give you the terminal type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With