When using the terminal, I want both my username and my hostname to have separate color schemes. Is that possible with Ubuntu's default terminal emulator(if not, is it possible in terminator?)?
Asked
Active
Viewed 9,272 times
2
-
3http://askubuntu.com/questions/13892/is-it-possible-to-color-the-prompt-in-bash and the link it connects to: http://www.ibm.com/developerworks/linux/library/l-tip-prompt/ – Rinzwind Mar 06 '16 at 10:51
1 Answers
3
You could wrap \h
in, e.g., \[\033[01;31m\]
and \[\033[00m\]
in ~/.bashrc
's $PS1
definition to make the host red; \[\033[00m\]
, which resets all the attributes, is already there in the default prompt, so you won't really need it, and I suggest commenting out $PS1
's definition and adding a line right after rather than editing the current $PS1
's definition for an easy rollback:
if [ "$color_prompt" = yes ]; then
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\[\033[01;31m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
This should work out-of-the-box on e.g. gnome-terminal
; on xterm
(and I'd guess in general on xterm
-based terminals), you'll also have to uncomment this line:
#force_color_prompt=yes
You can check out other available colors e.g. here.

kos
- 35,891
-
-
@MarioKamenjak It works for all terminals that support coloring through ANSI color escape sequences (for example the console,
gnome-terminal
andxterm
, but most if not allxterm
-based terminals will likely support that, though the palette could be more or less extensive). I suppose you're referring to Terminal (which isgnome-terminal
), so if that's the case yeah, it will work for Terminal. – kos Mar 06 '16 at 21:26 -
I had to uncomment force_color_prompt first. Anyway, it works now. Here is my color scheme: PS1='${debian_chroot:+($debian_chroot)}[\033[01;33m]\u[\033[01;36m]@[\033[01;36m]\h[\033[00m]:[\033[00m]\w[\033[00m]$' – Mario Kamenjak Mar 07 '16 at 15:32
-
This helped as well: http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/ I will accept your answer now. – Mario Kamenjak Mar 07 '16 at 15:32
-
@MarioKamenjak Which terminal? It shouldn't be necessary in
gnome-terminal
/xterm
(in fact my prompt is colored, butforce_color_prompt=yes
is still commented). – kos Mar 07 '16 at 15:42 -
@MarioKamenjak Ah I see, apparently it's actually required in
xterm
(and I'd guess also inxterm
-based terminals?). Thanks, I'll add that to the answer. – kos Mar 07 '16 at 15:46