diff options
Diffstat (limited to 'app-shells/bash/files')
| -rw-r--r-- | app-shells/bash/files/bashrc-r1 | 29 | ||||
| -rw-r--r-- | app-shells/bash/files/bashrc.d/10-gentoo-title-r3.bash | 77 |
2 files changed, 77 insertions, 29 deletions
diff --git a/app-shells/bash/files/bashrc-r1 b/app-shells/bash/files/bashrc-r1 deleted file mode 100644 index deb0ce97d4a7..000000000000 --- a/app-shells/bash/files/bashrc-r1 +++ /dev/null @@ -1,29 +0,0 @@ -# /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 diff --git a/app-shells/bash/files/bashrc.d/10-gentoo-title-r3.bash b/app-shells/bash/files/bashrc.d/10-gentoo-title-r3.bash new file mode 100644 index 000000000000..186763d07d9d --- /dev/null +++ b/app-shells/bash/files/bashrc.d/10-gentoo-title-r3.bash @@ -0,0 +1,77 @@ +# /etc/bash/bashrc.d/10-gentoo-title.bash + +# For information regarding the control sequences used, please refer to +# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html. + +genfun_set_win_title() { + # Advertise the fact that the presently running interactive shell will + # update the title. Doing so allows for its subprocesses to determine + # whether it is safe to set the title of their own accord. Note that 0 + # refers to the value of Ps within the OSC Ps ; Pt BEL sequence. + export SHELL_SETS_TITLE=0 + + # Sets the window title with the Set Text Parameters control 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() { + local prompt + + if [[ ${PROMPT_DIRTRIM} ]]; then + # Respect the value of PROMPT_DIRTRIM. If set as 0, the + # current working directory shall be shown in full. + prompt='\u@\h \w' + else + # Show the basename of the current working directory. + prompt='\u@\h \W' + fi + printf '\033]0;%s\007' "${prompt@P}" + } + + genfun_set_win_title +} + +unset -v SHELL_SETS_TITLE + +# Determine whether the terminal can handle the Set Text Parameters sequence. +# 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 +# is handled correctly. Quite rightly, this precludes many vintage terminals. +case ${TERM} in + alacritty*|contour|foot*|tmux*|xterm-ghostty) + # The terminal emulator also supports XTWINOPS. If the PTY was + # created by sshd(8) then push the current window title to the + # stack and arrange for it to be popped upon exiting. Xterm also + # supports this but there are far too many terminal emulators + # that falsely identify as being xterm-compatible. + if [[ ${SSH_TTY} && ${SSH_TTY} == "$(tty)" ]]; then + trap 'printf "\033[23;0t"' EXIT + printf '\033[22;0t' + fi + ;; + rxvt-unicode*|st-256color|xterm*) + # If the PTY was created by sshd(8) then proceed no further. + # Alas, there exist many operating environments in which the + # title would otherwise not be restored upon ssh(1) exiting. + # Those wanting for the title to be set regardless may adjust + # ~/.bashrc or create a bashrc.d drop-in to set PROMPT_COMMAND. + # For example, PROMPT_COMMAND=(genfun_set_win_title). + if [[ ${SSH_TTY} && ${SSH_TTY} == "$(tty)" ]]; then + return + fi + ;; + screen*) + # If the PTY was created by sshd(8) and screen(1) was launched + # prior to the SSH session beginning, as opposed to afterwards, + # proceed no further. It is another case in which there would be + # no guarantee of the title being restored upon ssh(1) exiting. + if [[ ! ${WINDOW} && ${SSH_TTY} && ${SSH_TTY} == "$(tty)" ]]; then + return + fi + ;; + *) + return +esac + +# Arrange for the title to be updated each time the primary prompt is displayed. +PROMPT_COMMAND+=('genfun_set_win_title') |
