diff options
| author | Kerin Millar <kfm@plushkava.net> | 2024-06-19 09:00:48 +0100 |
|---|---|---|
| committer | Sam James <sam@gentoo.org> | 2024-06-20 18:53:44 +0100 |
| commit | 68c208ecd6b805ebc7796d2b71ceef4614179a2d (patch) | |
| tree | 85cab33dd157da2a375d641d0a16c356735462b0 /app-shells/bash/files | |
| parent | ae5d12efc0a0e0755188ea43c7d644052a685ab1 (diff) | |
| download | gentoo-68c208ecd6b805ebc7796d2b71ceef4614179a2d.tar.gz gentoo-68c208ecd6b805ebc7796d2b71ceef4614179a2d.tar.bz2 gentoo-68c208ecd6b805ebc7796d2b71ceef4614179a2d.zip | |
app-shells/bash: uncouple 10-gentoo-color.bash; warn of bad .bashrc
Some users choose to manage /etc/bash/bashrc directly and disregard any
of its updates outright. Additionally, some users have ~/.bashrc as a
copy of ${FILESDIR}/bashrc which is either exact or which contains only
trivial modifications, meaning that the bashrc.d drop-ins end up being
sourced twice. For both of these scenarios, users will presently
encounter a diagnostic message indicating that the genfun_has_readline
function does not exist. In turn, that is because the function is
declared by /etc/bash/bashrc, while also being used by
/etc/bash/bashrc.d/10-gentoo-color.bash.
Since there is no particular need for 10-gentoo-color.bash to be coupled
in this manner, jettison the function. Instead, have bashrc consider the
exit status of the "shopt -s no_empty_cmd_completion" command and have
10-gentoo-color.bash perform its own test.
Additionally, implement a new bashrc.d drop-in named
"15-gentoo-bashrc-check.bash". Its purpose is to check whether ~/.bashrc
exists as a copy of ${FILESDIR}/bashrc and instruct the user as to how
to remedy the situation. After performing the check, it touches a file
under ${TMPDIR} so that it can subsequently avoid driving the user mad.
I recommend that this drop-in be removed one year hence. I disliked
having to do this but consider it to be in the public interest.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
Bug: https://bugs.gentoo.org/934523
Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'app-shells/bash/files')
| -rw-r--r-- | app-shells/bash/files/bashrc-r1 | 17 | ||||
| -rw-r--r-- | app-shells/bash/files/bashrc.d/10-gentoo-color.bash | 3 | ||||
| -rw-r--r-- | app-shells/bash/files/bashrc.d/15-gentoo-bashrc-check.bash | 24 |
3 files changed, 33 insertions, 11 deletions
diff --git a/app-shells/bash/files/bashrc-r1 b/app-shells/bash/files/bashrc-r1 index 6f4631568119..deb0ce97d4a7 100644 --- a/app-shells/bash/files/bashrc-r1 +++ b/app-shells/bash/files/bashrc-r1 @@ -5,16 +5,15 @@ if [[ $- != *i* ]]; then return fi -# A convenient function to determine whether bash has readline support. -genfun_has_readline() [[ $(shopt -p direxpand 2>/dev/null) ]] +# Disable errexit in case the user enabled it then chose to re-source this file. +shopt -u -o errexit -# The following two shell options require for bash to have readline support. -genfun_has_readline && +# Disable completion when the input buffer is empty. Mute STDERR because this +# option is only present in the case that bash was built with readline support. +shopt -s no_empty_cmd_completion 2>/dev/null && -# Disable completion when the input buffer is empty. -shopt -s no_empty_cmd_completion && - -# Append to HISTFILE rather than overwrite upon exiting, per bug #139609. +# Append to HISTFILE rather than overwrite upon exiting, per bug #139609. This +# option also requires for bash to have been built with readline support. shopt -s histappend # Initialise PROMPT_COMMAND as an array, which is permitted as of bash 5.1. @@ -28,5 +27,3 @@ for _ in /etc/bash/bashrc.d/*; do source "$_" fi done - -unset -f genfun_has_readline 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 6192bfaf4394..f0c5983b66e1 100644 --- a/app-shells/bash/files/bashrc.d/10-gentoo-color.bash +++ b/app-shells/bash/files/bashrc.d/10-gentoo-color.bash @@ -34,7 +34,8 @@ elif (( gentoo_color == 16777216 )); then export COLORTERM=truecolor fi -if (( gentoo_color <= 0 )) || ! genfun_has_readline; then +# For direxpand to be missing indicates that bash is lacking readline support. +if (( gentoo_color <= 0 )) || [[ ! $(shopt -p direxpand 2>/dev/null) ]]; then # Define a prompt without color. PS1='\u@\h \w \$ ' elif (( EUID == 0 )); then diff --git a/app-shells/bash/files/bashrc.d/15-gentoo-bashrc-check.bash b/app-shells/bash/files/bashrc.d/15-gentoo-bashrc-check.bash new file mode 100644 index 000000000000..8f2b0405c6b9 --- /dev/null +++ b/app-shells/bash/files/bashrc.d/15-gentoo-bashrc-check.bash @@ -0,0 +1,24 @@ +# /etc/bash/bashrc.d/15-gentoo-bashrc-check.bash + +# Some users have ~/.bashrc as a copy of ${FILESDIR}/bashrc which either matches +# exactly or is only trivially modified. Such is an improper state of affairs +# and results in the bashrc.d drop-ins being sourced twice. Warn them that they +# should use the skeleton file instead. This drop-in should be removed no sooner +# than one year from the date of its introduction. + +if [[ -e ${TMPDIR:-/tmp}/.gentoo-bashrc-check-${EUID} || ! -f ~/.bashrc ]]; then + return +fi + +{ + if grep -qxF 'for sh in /etc/bash/bashrc.d/* ; do' -- ~/.bashrc; then + cat >&3 <<'EOF' +WARNING! Your ~/.bashrc file is based on an old copy of /etc/bash/bashrc, which +is not intended for use within a home directory. Please either delete ~/.bashrc +or replace it with a copy of /etc/skel/.bashrc before optionally customizing it +further. Neglecting to do so may result in bash behaving unexpectedly. + +EOF + fi + touch -- "${TMPDIR:-/tmp}/.gentoo-bashrc-check-${EUID}" +} 3>&2 2>/dev/null |
