diff options
author | Kerin Millar <kfm@plushkava.net> | 2024-04-30 01:16:45 +0100 |
---|---|---|
committer | Sam James <sam@gentoo.org> | 2024-04-30 03:36:42 +0100 |
commit | 8771b2ce786bcfe249cd03dc1d994f13266ce5c7 (patch) | |
tree | 3c84da00cee9e3095e80de23a6136816b4b13b24 /app-shells/bash/files/bashrc.d/10-gentoo-color.bash | |
parent | dev-perl/ExtUtils-InstallPaths: add 0.13.0 (diff) | |
download | gentoo-8771b2ce786bcfe249cd03dc1d994f13266ce5c7.tar.gz gentoo-8771b2ce786bcfe249cd03dc1d994f13266ce5c7.tar.bz2 gentoo-8771b2ce786bcfe249cd03dc1d994f13266ce5c7.zip |
app-shells/bash: support -readline properly, GLOBSORT protection, misc cleanups
Address a regression whereby the new initialisation files were composing
a PS1 prompt containing '\[' and '\]' for builds without readline
support. These sequences are normally used to denote sequences of
non-printing characters but are not treated specially unless readline
support is present. This came up 12 years ago as bug #432338. SpanKY's
solution at the time was to have the ebuild monkey-patch
/etc/bash/bashrc with sed, disabling colour support outright for the
USE="-readline" case. Unsurprisingly, moving the colour-related code to
a distinct bashrc.d snippet had prevented this method from being
effective.
After deliberating over the matter, I reached the conclusion that there
are already too many ebuilds containing overly brittle code of this
sort. Therefore, I decided to implement a runtime check instead.
Specifically, it is implemented as a trivial function, which works by
checking whether the direxpand shell option exists. This function is now
used in a twofold manner. Firstly, it is used to determine whether the
no_empty_cmd_completion and histappend shell options should be set in
etc/bash/bashrc (both of those require readline). Secondly, it it used
to determine whether the prompt should _not_ be colourised in
/etc/bash/bashrc.d/10-gentoo-color.bash, even in the case that the
terminal is understood to support colour.
Doing it this way has a few immediate benefits. No longer will colour
support be needlessly disabled outright; there was never any sense in
doing that. Instead, users that elect to compile bash without readline -
for whatever reason - may continue to enjoy full colour support with
only the prompt being rendered in monochrome. Moreover, the ebuild has
been simplified as a consequence of being able to completely drop the
section that defined sed_args before proceeding to clumsily modify
/etc/skel/.bashrc (with no effect, mind) and /etc/bash/bashrc.
Render /etc/bash/bashrc.d processing safer by unsetting the GLOBSORT
variable beforehand. This variable, which is introduced by
bash-5.3-alpha, allows for the user to affect the order in which words
occur as a result of pathname expansion. While there is no question that
the feature is useful, it must not be allowed to influence the order in
which files residing under /etc/bash/bashrc.d are processed. That is,
users must be able to expect that the files are processed in an order
that is based solely on the effective collation.
Remove st-256color from the list of terminals whitelisted for colour
support. There was no need for it to be there because it can already be
matched by the *color* globbing pattern.
The latest round of ebuilds have been cleaned up and should be slightly
easier to maintain from hereon. Further, they are now shellcheck-clean,
albeit with two warning categories having been disabled in the global
scope (so chosen because they aren't particularly helpful in the course
of evaluating ebuilds). Finally, version 9999 has been updated so as to
be abreast of these developments.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'app-shells/bash/files/bashrc.d/10-gentoo-color.bash')
-rw-r--r-- | app-shells/bash/files/bashrc.d/10-gentoo-color.bash | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/app-shells/bash/files/bashrc.d/10-gentoo-color.bash b/app-shells/bash/files/bashrc.d/10-gentoo-color.bash index 66afdcaa9557..6192bfaf4394 100644 --- a/app-shells/bash/files/bashrc.d/10-gentoo-color.bash +++ b/app-shells/bash/files/bashrc.d/10-gentoo-color.bash @@ -14,28 +14,27 @@ elif unset -v COLORTERM; ! gentoo_color=$(tput colors 2>/dev/null); then # and which remain (somewhat) popular. This will rarely happen, so the # list need not be exhaustive. case ${TERM} in - *color* |\ - *direct* |\ - [Ekx]term* |\ - alacritty |\ - aterm |\ - dtterm |\ - foot* |\ - jfbterm |\ - linux |\ - mlterm |\ - rxvt* |\ - screen* |\ - st-256color |\ - tmux* |\ - wsvt25* ) gentoo_color=1 + *color* |\ + *direct* |\ + [Ekx]term* |\ + alacritty |\ + aterm |\ + dtterm |\ + foot* |\ + jfbterm |\ + linux |\ + mlterm |\ + rxvt* |\ + screen* |\ + tmux* |\ + wsvt25* ) gentoo_color=1 esac elif (( gentoo_color == 16777216 )); then # Truecolor support is available. Advertise it. export COLORTERM=truecolor fi -if (( gentoo_color <= 0 )); then +if (( gentoo_color <= 0 )) || ! genfun_has_readline; then # Define a prompt without color. PS1='\u@\h \w \$ ' elif (( EUID == 0 )); then @@ -47,7 +46,7 @@ else fi if (( gentoo_color > 0 )); then - # Colorize the output of grep and several coreutils utilities. + # Colorize the output of diff(1), grep(1) and a few coreutils utilities. for _ in diff dir grep ls vdir; do alias "$_=$_ --color=auto" done |