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?)?
1 Answer
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.
-
-
@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.– kosMar 6, 2016 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\]\$' Mar 7, 2016 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).– kosMar 7, 2016 at 15:42