17

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?

4 Answers 4

21

Why 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.

7
  • 29
    Which is sort of funny because I find it much easier to tell where the output is when the prompt has color.
    – chicks
    Dec 11, 2016 at 13:16
  • @chicks Well, at least it is easy to change it into a colourful prompt if one desires! Dec 11, 2016 at 13:21
  • 9
    I've been pondering for some years reaching the person who dared writing such a fallaciously pedantic, aggressive, pointless, totally arguable, on the border of being illogical, comment in a file that's copied in every user's home. Apr 22, 2019 at 1:32
  • @JohanBoulé 100% agree. total wtf to put such opinionated things in widely distributed defaults.
    – v.oddou
    May 28, 2019 at 2:30
6

(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.

3

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'
2
  • 1
    I like your idea of putting LC_COLLATE directly in the alias :) May 28, 2019 at 10:57
  • on a fresh Debian 12 VM, the path for me was /etc/skel/.bashrc (note the . on the filename) Aug 27 at 10:59
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .