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.
Hmm.. New bashrc works fine in tmux. Change was made wrt bug 208695
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.
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.
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.
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\\\]'
Sven: are you ok with the proposed screenrc change (adding windowlist) ?
(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!
To follow up on my last comment, I do not experience this issue anymore. Taking @shell-tools off this bug report.
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 ~/
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.
Created attachment 570088 [details, diff] bash set pane title for screen
I believe this bug to be addressed by both bash-5.1_p16-r8 and bash-5.2_p26-r1. Heui-mun Park, thank you for your insightful comment. Though I had not read it prior to submitting the bash revisions, I had reached a similar conclusion, though I ended up using '\033]2;%s\007' rather than '\033]0;%s\007' (the intent being to manipulate only the title). Employing the former sequence worked well in the course of my testing. However, if it is the case that there are many applications that take it upon themselves to employ the latter sequence, that may be a good argument for following suit. Incidentally, the present behaviour of portage is being investigated.