commit:     b40811ec316a630d6a48f185e6459f235c83413d
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Jul  6 22:59:56 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Jul  7 00:18:08 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b40811ec

app-shells/bash: add 5.2_p26-r8 with non-preliminary XTWINOPS support

The 5.2_p26-r7 revision contained (harmless) changes that were not yet
intended to be applied to the gentoo repo, owing to a miscommunication
between Sam and I. This commit applies the changes as were eventually
intended and, for this reason, the remainder of this commit message
shall be written accordingly. That is, as if no preceding commit had
been involved to get to this point.

...

Xterm is able to push and pop window titles to a stack and there are
several other terminal emulators that can do so, such as alacritty, foot
and tmux. Take advantage of this feature so as to reinstate automatic
window title setting in the case that the PTY is owned by sshd(8).
Unfortunately, there are a lot of terminal emulators that falsely
advertise themselves as being xterm-compatible, making it impossible to
reliably identify xterm itself. However, we can reliably identify
alacritty, foot and tmux so let's support those three to begin with.

The benefits conferred upon tmux are of a distinct nature, since it was
already the case that it was being whitelisted for title support.
Specifcally, the benefits are as follows:

- title restoration is supported even where tmux(1) is launched prior to ssh(1)
- title restoration is supported for nested instances of tmux

It should be noted that tmux does not forward titles to the outer
terminal emulator by default. Such can be arranged for with the
following configuration.

  set -g set-titles on
  set -g set-titles-string "#T"

Don't enable title setting for GNU screen in the case that the PTY is
owned by sshd(8) and screen(1) was launched prior to connecting with
ssh(1). This is a distinction that can be made by checking whether the
WINDOW variable is set in the environment.

Have the genfun_set_win_title function export a variable named
SHELL_SETS_TITLE upon the first occasion that it is called. Presently,
nothing responds to this variable but the intention is to eventually
have portage respond to it. Portage implements heuristics and behaviours
that are horrifyingly broken. For instance, it considers the mere
presence of PROMPT_COMMAND as somehow proving that the interactive shell
uses it for nothing other than to set the title, despite the fact that:

- the contents of PROMPT_COMMAND may be arbitrarily defined by the user
- the purpose of PROMPT_COMMAND is whatever the user may wish it to be
- nobody in their right mind would export PROMPT_COMMAND
- PROMPT_COMMAND can be an array since 5.1 (making it unexportable)

Worse still, in the event that portage is somehow able to ascertain the
value of PROMPT_COMMAND, it takes its first element and proceeds to
inject its value into an invocation of either sh, $SHELL or bash -c,
irrespective of the consequences. No, I'm not making this up.

As such, the purpose of the SHELL_SETS_TITLE variable is to act as a
straightforward indicator that an interactive shell exists as an
ancestor process and that it will take it upon itself to set a fresh
window title upon its primary prompt being displayed.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 .../bash/{bash-5.2_p26-r7.ebuild => bash-5.2_p26-r8.ebuild} | 12 ++++++------
 app-shells/bash/files/bashrc.d/10-gentoo-title-r1.bash      | 13 ++++++++++---
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/app-shells/bash/bash-5.2_p26-r7.ebuild 
b/app-shells/bash/bash-5.2_p26-r8.ebuild
similarity index 96%
rename from app-shells/bash/bash-5.2_p26-r7.ebuild
rename to app-shells/bash/bash-5.2_p26-r8.ebuild
index c46a593c82b0..1926aee81671 100644
--- a/app-shells/bash/bash-5.2_p26-r7.ebuild
+++ b/app-shells/bash/bash-5.2_p26-r8.ebuild
@@ -372,7 +372,7 @@ pkg_postinst() {
        read -r old_ver <<<"${REPLACING_VERSIONS}"
        if [[ ! $old_ver ]]; then
                :
-       elif ver_test "$old_ver" -ge "5.2" && ver_test "$old_ver" -ge 
"5.2_p26-r7"; then
+       elif ver_test "$old_ver" -ge "5.2" && ver_test "$old_ver" -ge 
"5.2_p26-r8"; then
                return
        fi
 
@@ -387,11 +387,11 @@ PROMPT_COMMAND variable are now advised to append their 
commands like so:
 PROMPT_COMMAND+=('custom command goes here')
 
 Gentoo no longer defaults to having bash set the window title in the case
-that the terminal is controlled by sshd(8), unless screen or tmux are in use
-or the terminal reliably supports saving and restoring the title (as
-alacritty and foot do). Those wanting to set the title unconditionally may
-adjust ~/.bashrc - or create a custom /etc/bash/bashrc.d drop-in - to set
-PROMPT_COMMMAND like so:
+that the terminal is controlled by sshd(8), unless screen is launched on the
+remote side or the terminal reliably supports saving and restoring the title
+(as alacritty, foot and tmux do). Those wanting for the title to be set
+regardless may adjust ~/.bashrc - or create a custom /etc/bash/bashrc.d
+drop-in - to set PROMPT_COMMMAND like so:
 
 PROMPT_COMMAND=(genfun_set_win_title)
 

diff --git a/app-shells/bash/files/bashrc.d/10-gentoo-title-r1.bash 
b/app-shells/bash/files/bashrc.d/10-gentoo-title-r1.bash
index 1dc7b63bf422..8e78b09a9daf 100644
--- a/app-shells/bash/files/bashrc.d/10-gentoo-title-r1.bash
+++ b/app-shells/bash/files/bashrc.d/10-gentoo-title-r1.bash
@@ -42,9 +42,7 @@ unset -v SHELL_SETS_TITLE
 # 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
-       screen*|tmux*)
-               ;;
-       alacritty|foot*)
+       alacritty|foot*|tmux*)
                # 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
@@ -66,6 +64,15 @@ case ${TERM} in
                        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

Reply via email to