commit:     1d15b220376e9da1251127d71f78203f5da3f9d7
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Jun 29 12:58:33 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Jun 30 17:25:03 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=1d15b220

app-shells/bash: fix title setting heuristic; set both icon name and title

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: 9ff9f8199ccf9d55fb1cf066cbbc791101894ab0
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-5.1_p16-r12.ebuild => bash-5.1_p16-r13.ebuild} | 37 ++++++++++++--------
 ...sh-5.2_p26-r5.ebuild => bash-5.2_p26-r6.ebuild} | 37 ++++++++++++--------
 ....3_alpha-r4.ebuild => bash-5.3_alpha-r5.ebuild} | 37 ++++++++++++--------
 app-shells/bash/bash-9999.ebuild                   | 40 ++++++++++++++--------
 .../bash/files/bashrc.d/10-gentoo-title.bash       | 13 +++----
 5 files changed, 102 insertions(+), 62 deletions(-)

diff --git a/app-shells/bash/bash-5.1_p16-r12.ebuild 
b/app-shells/bash/bash-5.1_p16-r13.ebuild
similarity index 89%
rename from app-shells/bash/bash-5.1_p16-r12.ebuild
rename to app-shells/bash/bash-5.1_p16-r13.ebuild
index cc9ce6983938..38b7451addc3 100644
--- a/app-shells/bash/bash-5.1_p16-r12.ebuild
+++ b/app-shells/bash/bash-5.1_p16-r13.ebuild
@@ -328,22 +328,31 @@ 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-r1"; then
+       elif ver_test "$old_ver" -ge "5.2" && ver_test "$old_ver" -ge 
"5.2_p26-r6"; then
                return
-       elif ver_test "$old_ver" -lt "5.2" && ver_test "$old_ver" -ge 
"5.1_p16-r8"; then
+       elif ver_test "$old_ver" -lt "5.2" && ver_test "$old_ver" -ge 
"5.1_p16-r13"; then
                return
        fi
 
-       ewarn "Files situated under /etc/bash/bashrc.d must now have a suffix 
of .sh or .bash."
-       ewarn ""
-       ewarn "Gentoo now defaults to defining PROMPT_COMMAND as an array. 
Depending on the"
-       ewarn "characteristics of the operating environment, this array may 
contain commands"
-       ewarn "to set the window and pane title. Users that choose to customise 
this variable"
-       ewarn "in ~/.bashrc are advised to append their commands, using the 
following syntax."
-       ewarn ""
-       ewarn "PROMPT_COMMAND+=('custom command goes here')"
-       ewarn ""
-       ewarn "Alternatively, users that wish to opt out of Gentoo's window 
title setting"
-       ewarn "behaviour may now do so by either unsetting PROMPT_COMMAND or by 
re-defining it"
-       ewarn "as desired. Previously, there was no formally supported method 
of opting out."
+       while read -r; do ewarn "${REPLY}"; done <<'EOF'
+Files situated under /etc/bash/bashrc.d must now have a suffix of .sh or .bash.
+
+Gentoo now defaults to defining PROMPT_COMMAND as an array. Depending on the
+characteristics of the operating environment, this array may contain a command
+to set the terminal's window title. Those already choosing to customise the
+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 manipulate the window title in the 
case
+that the terminal is controlled by sshd(8), unless screen or tmux are in use.
+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:
+
+PROMPT_COMMAND=(genfun_set_win_title)
+
+Those who would prefer for bash never to interfere with the window title may
+now opt out of the default title setting behaviour, either with the "unset -v
+PROMPT_COMMAND" command or by re-defining PROMPT_COMMAND as desired.
+EOF
 }

diff --git a/app-shells/bash/bash-5.2_p26-r5.ebuild 
b/app-shells/bash/bash-5.2_p26-r6.ebuild
similarity index 90%
rename from app-shells/bash/bash-5.2_p26-r5.ebuild
rename to app-shells/bash/bash-5.2_p26-r6.ebuild
index e8eaa353cf21..4350a8a719c3 100644
--- a/app-shells/bash/bash-5.2_p26-r5.ebuild
+++ b/app-shells/bash/bash-5.2_p26-r6.ebuild
@@ -372,22 +372,31 @@ 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-r1"; then
+       elif ver_test "$old_ver" -ge "5.2" && ver_test "$old_ver" -ge 
"5.2_p26-r6"; then
                return
-       elif ver_test "$old_ver" -lt "5.2" && ver_test "$old_ver" -ge 
"5.1_p16-r8"; then
+       elif ver_test "$old_ver" -lt "5.2" && ver_test "$old_ver" -ge 
"5.1_p16-r13"; then
                return
        fi
 
-       ewarn "Files situated under /etc/bash/bashrc.d must now have a suffix 
of .sh or .bash."
-       ewarn ""
-       ewarn "Gentoo now defaults to defining PROMPT_COMMAND as an array. 
Depending on the"
-       ewarn "characteristics of the operating environment, this array may 
contain commands"
-       ewarn "to set the window and pane title. Users that choose to customise 
this variable"
-       ewarn "in ~/.bashrc are advised to append their commands, using the 
following syntax."
-       ewarn ""
-       ewarn "PROMPT_COMMAND+=('custom command goes here')"
-       ewarn ""
-       ewarn "Alternatively, users that wish to opt out of Gentoo's window 
title setting"
-       ewarn "behaviour may now do so by either unsetting PROMPT_COMMAND or by 
re-defining it"
-       ewarn "as desired. Previously, there was no formally supported method 
of opting out."
+       while read -r; do ewarn "${REPLY}"; done <<'EOF'
+Files situated under /etc/bash/bashrc.d must now have a suffix of .sh or .bash.
+
+Gentoo now defaults to defining PROMPT_COMMAND as an array. Depending on the
+characteristics of the operating environment, this array may contain a command
+to set the terminal's window title. Those already choosing to customise the
+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 manipulate the window title in the 
case
+that the terminal is controlled by sshd(8), unless screen or tmux are in use.
+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:
+
+PROMPT_COMMAND=(genfun_set_win_title)
+
+Those who would prefer for bash never to interfere with the window title may
+now opt out of the default title setting behaviour, either with the "unset -v
+PROMPT_COMMAND" command or by re-defining PROMPT_COMMAND as desired.
+EOF
 }

diff --git a/app-shells/bash/bash-5.3_alpha-r4.ebuild 
b/app-shells/bash/bash-5.3_alpha-r5.ebuild
similarity index 90%
rename from app-shells/bash/bash-5.3_alpha-r4.ebuild
rename to app-shells/bash/bash-5.3_alpha-r5.ebuild
index 9699a659026a..c0e5e68f43a5 100644
--- a/app-shells/bash/bash-5.3_alpha-r4.ebuild
+++ b/app-shells/bash/bash-5.3_alpha-r5.ebuild
@@ -371,22 +371,31 @@ 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-r1"; then
+       elif ver_test "$old_ver" -ge "5.2" && ver_test "$old_ver" -ge 
"5.2_p26-r6"; then
                return
-       elif ver_test "$old_ver" -lt "5.2" && ver_test "$old_ver" -ge 
"5.1_p16-r8"; then
+       elif ver_test "$old_ver" -lt "5.2" && ver_test "$old_ver" -ge 
"5.1_p16-r13"; then
                return
        fi
 
-       ewarn "Files situated under /etc/bash/bashrc.d must now have a suffix 
of .sh or .bash."
-       ewarn ""
-       ewarn "Gentoo now defaults to defining PROMPT_COMMAND as an array. 
Depending on the"
-       ewarn "characteristics of the operating environment, this array may 
contain commands"
-       ewarn "to set the window and pane title. Users that choose to customise 
this variable"
-       ewarn "in ~/.bashrc are advised to append their commands, using the 
following syntax."
-       ewarn ""
-       ewarn "PROMPT_COMMAND+=('custom command goes here')"
-       ewarn ""
-       ewarn "Alternatively, users that wish to opt out of Gentoo's window 
title setting"
-       ewarn "behaviour may now do so by either unsetting PROMPT_COMMAND or by 
re-defining it"
-       ewarn "as desired. Previously, there was no formally supported method 
of opting out."
+       while read -r; do ewarn "${REPLY}"; done <<'EOF'
+Files situated under /etc/bash/bashrc.d must now have a suffix of .sh or .bash.
+
+Gentoo now defaults to defining PROMPT_COMMAND as an array. Depending on the
+characteristics of the operating environment, this array may contain a command
+to set the terminal's window title. Those already choosing to customise the
+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 manipulate the window title in the 
case
+that the terminal is controlled by sshd(8), unless screen or tmux are in use.
+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:
+
+PROMPT_COMMAND=(genfun_set_win_title)
+
+Those who would prefer for bash never to interfere with the window title may
+now opt out of the default title setting behaviour, either with the "unset -v
+PROMPT_COMMAND" command or by re-defining PROMPT_COMMAND as desired.
+EOF
 }

diff --git a/app-shells/bash/bash-9999.ebuild b/app-shells/bash/bash-9999.ebuild
index ae661e409da8..7ef121e1c56f 100644
--- a/app-shells/bash/bash-9999.ebuild
+++ b/app-shells/bash/bash-9999.ebuild
@@ -311,6 +311,9 @@ src_install() {
        insinto /etc/bash/bashrc.d
        my_prefixify DIR_COLORS "${FILESDIR}"/bashrc.d/10-gentoo-color.bash | 
newins - 10-gentoo-color.bash
        doins "${FILESDIR}"/bashrc.d/10-gentoo-title.bash
+       if [[ ! ${EPREFIX} ]]; then
+               doins "${FILESDIR}"/bashrc.d/15-gentoo-bashrc-check.bash
+       fi
 
        insinto /etc/skel
        for f in bash{_logout,_profile,rc}; do
@@ -368,22 +371,31 @@ 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-r1"; then
+       elif ver_test "$old_ver" -ge "5.2" && ver_test "$old_ver" -ge 
"5.2_p26-r6"; then
                return
-       elif ver_test "$old_ver" -lt "5.2" && ver_test "$old_ver" -ge 
"5.1_p16-r8"; then
+       elif ver_test "$old_ver" -lt "5.2" && ver_test "$old_ver" -ge 
"5.1_p16-r13"; then
                return
        fi
 
-       ewarn "Files situated under /etc/bash/bashrc.d must now have a suffix 
of .sh or .bash."
-       ewarn ""
-       ewarn "Gentoo now defaults to defining PROMPT_COMMAND as an array. 
Depending on the"
-       ewarn "characteristics of the operating environment, this array may 
contain commands"
-       ewarn "to set the window and pane title. Users that choose to customise 
this variable"
-       ewarn "in ~/.bashrc are advised to append their commands, using the 
following syntax."
-       ewarn ""
-       ewarn "PROMPT_COMMAND+=('custom command goes here')"
-       ewarn ""
-       ewarn "Alternatively, users that wish to opt out of Gentoo's window 
title setting"
-       ewarn "behaviour may now do so by either unsetting PROMPT_COMMAND or by 
re-defining it"
-       ewarn "as desired. Previously, there was no formally supported method 
of opting out."
+       while read -r; do ewarn "${REPLY}"; done <<'EOF'
+Files situated under /etc/bash/bashrc.d must now have a suffix of .sh or .bash.
+
+Gentoo now defaults to defining PROMPT_COMMAND as an array. Depending on the
+characteristics of the operating environment, this array may contain a command
+to set the terminal's window title. Those already choosing to customise the
+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 manipulate the window title in the 
case
+that the terminal is controlled by sshd(8), unless screen or tmux are in use.
+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:
+
+PROMPT_COMMAND=(genfun_set_win_title)
+
+Those who would prefer for bash never to interfere with the window title may
+now opt out of the default title setting behaviour, either with the "unset -v
+PROMPT_COMMAND" command or by re-defining PROMPT_COMMAND as desired.
+EOF
 }

diff --git a/app-shells/bash/files/bashrc.d/10-gentoo-title.bash 
b/app-shells/bash/files/bashrc.d/10-gentoo-title.bash
index 003e364ff072..2b2e23347784 100644
--- a/app-shells/bash/files/bashrc.d/10-gentoo-title.bash
+++ b/app-shells/bash/files/bashrc.d/10-gentoo-title.bash
@@ -20,17 +20,18 @@ genfun_set_win_title() {
        # the title bar to be affected.
        genfun_set_win_title() {
                genfun_sanitise_cwd
-               printf '\033]2;%s@%s - %s\007' "${USER}" "${HOSTNAME%%.*}" 
"${_cwd}"
+               printf '\033]0;%s@%s - %s\007' "${USER}" "${HOSTNAME%%.*}" 
"${_cwd}"
        }
 
        genfun_set_win_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. Users wishing to coerce the historical
-# behaviour have the option of setting PROMPT_COMMAND=(genfun_set_win_title).
-if [[ ${SSH_TTY} && ${SSH_TTY} == "$(tty)" ]]; then
+# 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
 

Reply via email to