gentoo-ebuilds/app-shells/bash/files/bashrc-r1
Kerin Millar 68c208ecd6
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>
2024-06-20 18:53:44 +01:00

29 lines
894 B
Text

# /etc/bash/bashrc
# Proceed no further in the case of a non-interactive shell.
if [[ $- != *i* ]]; then
return
fi
# Disable errexit in case the user enabled it then chose to re-source this file.
shopt -u -o errexit
# 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 &&
# 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.
PROMPT_COMMAND=()
# Don't let the user influence the order of sourcing for bash 5.3 or greater.
unset -v GLOBSORT
for _ in /etc/bash/bashrc.d/*; do
if [[ $_ == *.@(bash|sh) && -r $_ ]]; then
source "$_"
fi
done