app-shells/bash/files/bashrc.d: files from ::gentoo

Signed-off-by: Alarig Le Lay <alarig@swordarmor.fr>
This commit is contained in:
Alarig Le Lay 2024-07-01 14:36:09 +02:00
parent e268ff6dbb
commit c611d04191
Signed by: alarig
GPG key ID: 7AFE62C6DF8BCDEC
3 changed files with 58 additions and 37 deletions

View file

@ -34,7 +34,8 @@ elif (( gentoo_color == 16777216 )); then
export COLORTERM=truecolor export COLORTERM=truecolor
fi 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. # Define a prompt without color.
PS1='\u@\h \w \$ ' PS1='\u@\h \w \$ '
elif (( EUID == 0 )); then elif (( EUID == 0 )); then

View file

@ -1,41 +1,41 @@
# /etc/bash/bashrc.d/10-gentoo-title.bash # /etc/bash/bashrc.d/10-gentoo-title.bash
# Set window title with the Title Definition String sequence. For screen, the genfun_set_win_title() {
# sequence defines the window title (%t) and for tmux, the pane_title (#T). # Assigns the basename of the current working directory, having
# For tmux to be affected requires that its allow-rename option be enabled. # sanitised it with @Q parameter expansion. Useful for paths containing
# https://www.gnu.org/software/screen/manual/html_node/Control-Sequences.html # newlines and such. As a special case, names consisting entirely of
case ${TERM} in # graphemes shall not undergo the expansion, for reasons of cleanliness.
screen*|tmux*) genfun_sanitise_cwd() {
genfun_set_pane_title() { _cwd=${PWD##*/}
printf '\033k%s\033\\' "${HOSTNAME%%.*}" if [[ ! ${_cwd} ]]; then
} _cwd=${PWD}
PROMPT_COMMAND+=('genfun_set_pane_title') elif [[ ${_cwd} == *[![:graph:]]* ]]; then
;; _cwd=${_cwd@Q}
*)
# If the TTY is that of sshd(8) then proceed no further. Alas,
# there exist many operating environments in which the window
# title would otherwise not be restored upon ssh(1) exiting.
if [[ ${SSH_TTY} && ${SSH_TTY} == "$(tty)" ]]; then
return
fi fi
esac }
# Assigns the basename of the current working directory, having sanitised it # Sets the window title with the Set Text Parameters sequence. For
# with @Q parameter expansion. Useful for paths containing newlines and such. # screen, the sequence defines the hardstatus (%h) and for tmux, the
# As a special case, names consisting entirely of graphemes shall not undergo # pane_title (#T). For graphical terminal emulators, it is normal for
# the parameter expansion, for reasons of cleanliness. # the title bar to be affected.
genfun_sanitise_cwd() { genfun_set_win_title() {
_cwd=${PWD##*/} genfun_sanitise_cwd
if [[ ! ${_cwd} ]]; then printf '\033]0;%s@%s - %s\007' "${USER}" "${HOSTNAME%%.*}" "${_cwd}"
_cwd=${PWD} }
elif [[ ${_cwd} == *[![:graph:]]* ]]; then
_cwd=${_cwd@Q} genfun_set_win_title
fi
} }
# Set window title with the Set Text Parameters sequence. For screen, the # Proceed no further if the TTY is that of sshd(8) and if not running a terminal
# sequence defines the hardstatus (%h) and for tmux, the window_name (#W). # multiplexer. Alas, there exist many operating environments in which the window
# For graphical terminal emulators, it is normal for the title bar be affected. # title would otherwise not be restored upon ssh(1) exiting. Those who wish for
# the title to be set unconditionally may adjust ~/.bashrc - or create a custom
# bashrc.d drop-in - to define PROMPT_COMMAND=(genfun_set_win_title).
if [[ ${SSH_TTY} && ${TERM} != @(screen|tmux)* && ${SSH_TTY} == "$(tty)" ]]; then
return
fi
# Determine whether the terminal can handle the Set Text Parameters sequence.
# The only terminals permitted here are those for which there is empirical # The only terminals permitted here are those for which there is empirical
# evidence that the sequence is supported and that the UTF-8 character encoding # evidence that the sequence is supported and that the UTF-8 character encoding
# is handled correctly. Quite rightly, this precludes many vintage terminals. # is handled correctly. Quite rightly, this precludes many vintage terminals.
@ -48,9 +48,5 @@ case ${TERM} in
st-256color |\ st-256color |\
tmux* |\ tmux* |\
xterm* ) xterm* )
genfun_set_win_title() {
genfun_sanitise_cwd
printf '\033]2;%s@%s - %s\007' "${USER}" "${HOSTNAME%%.*}" "${_cwd}"
}
PROMPT_COMMAND+=('genfun_set_win_title') PROMPT_COMMAND+=('genfun_set_win_title')
esac esac

View file

@ -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