I have been searching about why the default Debian shell is colourless and couldn't find a answer.
Why is the Debian shell (bash) colourless by default?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityWhy is the Debian shell (bash) colourless by default?
Because of this (from .bashrc
on a vanilla Debian install, emphasis mine):
# uncomment for a colored prompt, if the terminal has the capability; turned # off by default to not distract the user: the focus in a terminal window # should be on the output of commands, not on the prompt #force_color_prompt=yes if [ -n "$force_color_prompt" ]; then if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then # We have color support; assume it's compliant with Ecma-48 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such # a case would tend to support setf rather than setaf.) color_prompt=yes else color_prompt= fi fi
In other words, this is "a feature", or a design choice if you will.
(The original version of the question suggested it was about root’s shell; I’m leaving this here because it might be useful for users wondering specifically about that.)
In root’s case, the default prompt is colourless because /etc/profile
— or rather, /etc/bash.bashrc
— defines a very simple prompt:
# set a fancy prompt (non-color, overwrite the one in /etc/profile)
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
and root
’s default .bashrc
doesn’t override it:
# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022
See Where do /root/.bashrc and /root/.profile come from on a Debian system? for more details.
Because this was the top result for 'how to colorize root shell in debian' search I am posting my solution here: copy and overwrite /root/.bashrc
with the /etc/skel/bashrc
file.
This file is much more robust than the installed for root
and is also the default used for any new users created on the system.
Below are ls coloring excerpts I've tweaked over the years
alias la='LS_COLORS="mh=1;37" ls -A'
alias l='LS_COLORS="mh=1;37" ls -CF'
alias ll='LC_COLLATE=C LS_COLORS="mh=1;37" ls -lA --si --group-directories-first'
/etc/skel/.bashrc
(note the .
on the filename)
Aug 27 at 10:59
I have ended up with @daniel-sokolowski suggestion to look at /etc/skel/.bashrc
.
But important note that according bash documetntation a [ -z "$PS1" ]
test is common way to distinct interactive shell vs non-interactive.
This way when you add
# part from /etc/skel/.bashrc
...
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
you expose PS1=
for any kind of shell and it may break non-interactive commands like
ssh your-server ls -la
bash completion on: scp ssh://foo:/bar/<TAB>
vim scp://your-server//some/file
This commands will be broken when unwanted stdout happen from scripts intended to be part of interactive shells only.
This way complete solution is to wrap block in [ ! -z "$PS1" ]
test
...
if [ ! -z "$PS1" ]; then
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
fi
unset color_prompt force_color_prompt