#988383 bash: improve /etc/skel/.bashrc’s colour capability detection

Package:
bash
Source:
bash
Description:
GNU Bourne Again SHell
Submitter:
Christoph Anton Mitterer
Date:
2021-05-13 03:06:03 UTC
Severity:
wishlist
#988383#5
Date:
2021-05-11 14:19:25 UTC
From:
To:
Hey.

/etc/skel/.bashrc uses:
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

to detect whether the terminal supports a colourised prompt or not.


1) Could you please add "linux" to the list. That seems to be what the
kernel console uses, and I guess this always supports colours?
(Haven't checked though, whether there are any kernel parameters or
config options that would allow to disable colour support).


2) Additionally or alternatively one could add a more generic way of
detection.

Perhaps something like:
if [ -x /usr/bin/tput ]; then
	colour_support="$(tput colors 2> /dev/null)"
	if [ $? -eq 0  -a  "${colour_support}" -gt 2 ]; then
		color_prompt=yes
	fi
	unset colour_support
fi

This could be made as the fallback for the current case construct, which
could still list the TERM values known to have colours, e.g. like:
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
    *)
    [the above]
esac


Cheers,
Chris.

#988383#10
Date:
2021-05-11 14:29:59 UTC
From:
To:
Oh and maybe it's better to test for more colours, e.g.
  "${colour_support}" -gt 8
than just 2.

#988383#15
Date:
2021-05-13 03:02:26 UTC
From:
To:
For (1):

I guess adding just "linux" is not enough.
E.g. screen sets TERM to "screen.linux", when run on the kernel
console; and maybe tmux does something similar?

Not sure though, whether it's good to simply add "*linux"