app-shells/bash/files/bashrc.d: files from ::gentoo
Signed-off-by: Alarig Le Lay <alarig@swordarmor.fr>
This commit is contained in:
parent
e268ff6dbb
commit
c611d04191
|
@ -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
|
||||||
|
|
|
@ -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() {
|
|
||||||
printf '\033k%s\033\\' "${HOSTNAME%%.*}"
|
|
||||||
}
|
|
||||||
PROMPT_COMMAND+=('genfun_set_pane_title')
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
# 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
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Assigns the basename of the current working directory, having sanitised it
|
|
||||||
# with @Q parameter expansion. Useful for paths containing newlines and such.
|
|
||||||
# As a special case, names consisting entirely of graphemes shall not undergo
|
|
||||||
# the parameter expansion, for reasons of cleanliness.
|
|
||||||
genfun_sanitise_cwd() {
|
|
||||||
_cwd=${PWD##*/}
|
_cwd=${PWD##*/}
|
||||||
if [[ ! ${_cwd} ]]; then
|
if [[ ! ${_cwd} ]]; then
|
||||||
_cwd=${PWD}
|
_cwd=${PWD}
|
||||||
elif [[ ${_cwd} == *[![:graph:]]* ]]; then
|
elif [[ ${_cwd} == *[![:graph:]]* ]]; then
|
||||||
_cwd=${_cwd@Q}
|
_cwd=${_cwd@Q}
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Sets the window title with the Set Text Parameters sequence. For
|
||||||
|
# screen, the sequence defines the hardstatus (%h) and for tmux, the
|
||||||
|
# pane_title (#T). For graphical terminal emulators, it is normal for
|
||||||
|
# the title bar to be affected.
|
||||||
|
genfun_set_win_title() {
|
||||||
|
genfun_sanitise_cwd
|
||||||
|
printf '\033]0;%s@%s - %s\007' "${USER}" "${HOSTNAME%%.*}" "${_cwd}"
|
||||||
|
}
|
||||||
|
|
||||||
|
genfun_set_win_title
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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
|
||||||
|
|
24
app-shells/bash/files/bashrc.d/15-gentoo-bashrc-check.bash
Normal file
24
app-shells/bash/files/bashrc.d/15-gentoo-bashrc-check.bash
Normal 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
|
Loading…
Reference in a new issue