mirror of
https://anongit.gentoo.org/git/repo/gentoo.git
synced 2025-07-22 06:57:59 +02:00
In bug #934732, Sven Wegener requested for bash to refrain from setting
the "internal" window title. That is, the window title (%t) of GNU
screen and the window_name (#W) of tmux. A patch was attached to the
bug, which I acknowledged and which was subsequently applied by Sven.
Unfortunately - and perhaps owing to my eagerness to have the matter be
resolved - I did not notice that the patch introduces a regression. The
regression is that both screen and tmux are no longer exempted from the
sshd(8) check, resulting in neither the hardstatus (%h) being set for
the former, nor the pane_title (#T) for the latter. This commit restores
the intended behaviour.
In comment #10 of bug #550104, Heui-mun Park makes a compelling case
that the "\033]0;" variant of the Set Text Parameters sequence should be
preferred over other variants. The difference is that it sets the "icon
name" in addition to the "window title". Indeed, I have found that most
applications that employ the sequence make use of this more
comprehensive variant. For many users, such a distinction would amount
to being little more than an artifact of history. Nevertheless, it makes
perfect sense for 10-gentoo-title.bash to be aligned with the practices
of others in this regard. Make it so.
Improve the commentary in 10-gentoo-title.bash, along with the accuracy
and utility of the information conveyed by the ewarn comands in the
ebuilds.
Have the live ebuild (version 9999) install 15-gentoo-bashrc-check.bash,
just as the other recent ebuilds do. It's simpler from a maintenance
standpoint for there to be as few differences between them as is
possible.
Fixes: 9ff9f8199c
Signed-off-by: Kerin Millar <kfm@plushkava.net>
Signed-off-by: Sam James <sam@gentoo.org>
52 lines
1.9 KiB
Bash
52 lines
1.9 KiB
Bash
# /etc/bash/bashrc.d/10-gentoo-title.bash
|
|
|
|
genfun_set_win_title() {
|
|
# 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 expansion, for reasons of cleanliness.
|
|
genfun_sanitise_cwd() {
|
|
_cwd=${PWD##*/}
|
|
if [[ ! ${_cwd} ]]; then
|
|
_cwd=${PWD}
|
|
elif [[ ${_cwd} == *[![:graph:]]* ]]; then
|
|
_cwd=${_cwd@Q}
|
|
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
|
|
}
|
|
|
|
# Proceed no further if the TTY is that of sshd(8) and if not running a terminal
|
|
# multiplexer. Alas, there exist many operating environments in which the window
|
|
# 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
|
|
# evidence that the sequence is supported and that the UTF-8 character encoding
|
|
# is handled correctly. Quite rightly, this precludes many vintage terminals.
|
|
# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
|
|
case ${TERM} in
|
|
alacritty |\
|
|
foot* |\
|
|
rxvt-unicode* |\
|
|
screen* |\
|
|
st-256color |\
|
|
tmux* |\
|
|
xterm* )
|
|
PROMPT_COMMAND+=('genfun_set_win_title')
|
|
esac
|