Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 550104 - app-shells/bash - bashrc does not set the window title correctly for gnu screen
Summary: app-shells/bash - bashrc does not set the window title correctly for gnu screen
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-22 03:52 UTC by redneb
Modified: 2019-03-21 04:58 UTC (History)
8 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
bash set pane title for tmux (xterm-window-title-escape-codes-for-tmux.patch,682 bytes, patch)
2019-03-21 04:57 UTC, Heui-mun Park
Details | Diff
bash set pane title for screen (xterm-window-title-escape-codes-for-screen.patch,418 bytes, patch)
2019-03-21 04:58 UTC, Heui-mun Park
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description redneb 2015-05-22 03:52:39 UTC
I just upgraded to app-shells/bash-4.3_p33-r2 and the new bash comes with a bashrc that uses $PS1 to set the window title instead of $PROMPT_COMMAND. As that change implemented, the code for setting the window title under gnu-screen was changed and not it does not work correctly in my system. The relevant line now is:

    PS1='\[\033k\u@\h:\w\033\\\]'

If I change the "k" into an "_" (which is what we had in the past), then everything works correctly again.
Comment 1 Alexander Tsoy 2015-05-22 17:26:44 UTC
Hmm.. New bashrc works fine in tmux. Change was made wrt bug 208695
Comment 2 redneb 2015-05-29 16:42:48 UTC
I think the best approach here is to have screen update the xterm window title and not the screen window title (i.e. the thing that you see with Ctrl-a "), just for the sake of consistency. So if I say type some emerge command in xterm, the xterm window title will be updated no matter if emerge is run directly or inside a screen session.

As for the users who like to see the screen window title be updated, they can always adjust their bashrc, or the may use something like this:

    windowlist string "%3n %h%=%f"

in their screenrc.

But the default should be chosen so that it is less surprising for the majority of users.
Comment 3 redneb 2015-05-29 16:46:36 UTC
Furthermore, changing the xterm window title in screen can be done with the same code as other xterm compatible terminals, so we can remove the special treatment of screen and merge it with the line that handles the other terminals, i.e. we could have something like that:

case ${TERM} in
	xterm*|rxvt*|Eterm*|aterm|kterm|gnome*|interix|konsole*|screen*)
		PS1='\[\033]0;\u@\h:\w\007\]'
		;;
	*)
		unset PS1
		;;

This is nicer, cleaner, and leaner.
Comment 4 Andrew Miller 2015-06-07 05:13:23 UTC
FYI, this affects all screen users, but also some tmux users (who have enabled automatic window renaming).

Steps to reproduce with tmux:

1. emerge app-misc/tmux =app-shells/bash-4.3_p33-r2
2. echo 'set -g automatic-rename on' > ~/.tmux.conf
3. tmux
4. cd /usr/portage/app-shells/bash/files (or any directory with a long path).

Notice how the window title becomes really long. If you open some more tmux windows, it becomes difficult to navigate.
Comment 5 SpanKY gentoo-dev 2015-06-07 19:52:51 UTC
to summarize ...

the previous bashrc was setting screen's hardware status line (the _ escape sequence).  that works with some terminals (like xterm) because screen will link its hardware status line directly to the terminal's window title:
  termcapinfo xterm* 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen\007'
but obviously that only works with xterm currently.  screen probably should list all the same terminals as bashrc.

the new bashrc sets screen's window title (the k escape sequence).  the default window title is fairly useless (imo) as it just shows the initial program's name ("bash").  the whole point of these defaults is to provide something useful.  setting the window title falls both within the original intention and this.

using ]0 for screen would work because it has a compatibility hack in place so that it works the same as setting the hardware status line directly:
     ESC ] 0 ; string ^G     (A)     Operating System Command (Hardstatus,
                                     xterm title hack)

since screen is already installing its own custom screenrc, we could update the default to include the hardware status line:
  windowlist string "%3n %h%=%f"

or we could change bashrc to update both fields:
  PS1='\[\033k\u@\h:\w\033\\\033_\u@\h:\w\033\\\]'
Comment 6 SpanKY gentoo-dev 2015-07-28 06:52:23 UTC
Sven: are you ok with the proposed screenrc change (adding windowlist) ?
Comment 7 Patrice Clement gentoo-dev 2015-08-24 13:52:52 UTC
(In reply to Andrew Miller from comment #4)
> FYI, this affects all screen users, but also some tmux users (who have
> enabled automatic window renaming).
> 
> Steps to reproduce with tmux:
> 
> 1. emerge app-misc/tmux =app-shells/bash-4.3_p33-r2
> 2. echo 'set -g automatic-rename on' > ~/.tmux.conf
> 3. tmux
> 4. cd /usr/portage/app-shells/bash/files (or any directory with a long path).
> 
> Notice how the window title becomes really long. If you open some more tmux
> windows, it becomes difficult to navigate.

Yes indeed.

Could someone please merge this patch to get things back to normal? I've been wondering why tmux was behaving weirdly (freaking long window titles) and I now know why!
Comment 8 Patrice Clement gentoo-dev 2017-08-19 17:50:20 UTC
To follow up on my last comment, I do not experience this issue anymore. Taking @shell-tools off this bug report.
Comment 9 Gleb 2018-02-24 08:53:18 UTC
There is another issue with Midnight Commander, which doesn't understand the sequence which changes screen window title with k sequence.

The prompt in mc will look like this then:
username@hostname:username@hostname ~/
Comment 10 Heui-mun Park 2019-03-21 04:57:34 UTC
Created attachment 570086 [details, diff]
bash set pane title for tmux

I may have to comment about this window title escape codes problem wrt tmux,
bash, vim and portage's output.py.

tmux supports two different kinds of titles for applications to be able to
change the actual window title under user's preference('set-titles on',
'set-titles-string' with '#W'/'#T' and 'allow-rename on').
One is pane title('#T' in tmux format strings), which applications can send to
tmux with '\033]0;%s\007' of XTerm's escape codes for compatibility or with
'\033]0;%s\033\\' according to tmux manual.
The other is window title('#W' in the format string and 'allow-rename on') with
'\033k%s\033\\' as the same for screen.

The problem is if applications are configured to use different codes among each
other and tmux is configured to show both titles on the actual window title,
weird things can happen.  More detailed case is in Bug680022#c3.

Long story short, to minimize potential problem, I suggest across the system
applications that can send title escape codes be configured to use the same code
unless it's for sure to use the other one.  Since portage/outout.py is with
XTerm's and vim is also with it if not modified its t_ts/t_fs variables,
bashrc's window title escape codes may as well be '\033]0;%s\007' for tmux too.

One of the attachment is a patch reflecting this suggestion as long as tmux is
configured to set TERM=tmux or tmux-256color with its 'default-terminal' option
leaving screen unaffected.  Or maybe bashrc set the code to XTerm's for screen
also, unless that's not hurting screen, tmux would not need to change TERM and
PS1 to get bash to update its pane title.  The other patch is for this scenario.

In anyway it gives more consistent UX for tmux, more compatible window title
setting for applications inside or outside tmux and less glitches.  Although I
am not sure about the case with screen.
Comment 11 Heui-mun Park 2019-03-21 04:58:21 UTC
Created attachment 570088 [details, diff]
bash set pane title for screen