screen-profiles does not update gnome-terminal title

Bug #338722 reported by Dominic Evans
28
This bug affects 4 people
Affects Status Importance Assigned to Milestone
byobu
Invalid
Wishlist
Unassigned
screen (Ubuntu)
Confirmed
Wishlist
Unassigned

Bug Description

# Abstract

When using screen + screen-profiles remotely, the terminal title is never updated.

# Explanation

When ssh'ing in gnome-terminal to a remote machine normally, the window title is correctly updated when running programs, moving between directories etc. to display the remote machine information just as if on the local machine.

However, when using screen+screen-profiles this is not the case, the title is never updated from what it was last set as by the local machine.

In contrast, when using screen via ssh on a remote RHEL5 box, the title is correctly updated (prefixed by [screen 0: bash] etc.)

Revision history for this message
Dustin Kirkland  (kirkland) wrote :

Hi Dominic, would you mind attaching a couple of screen shots to demonstrate this behavior?

:-Dustin

Revision history for this message
Dustin Kirkland  (kirkland) wrote : Re: [Bug 338722] [NEW] screen-profiles does not update gnome-terminal title

Googling around, there seem to be a *lot* of bugs that affect
screen+gnome-terminal. Most of them have work arounds involving
setting PS1 and/or EXPORT_COMMAND correctly.

I haven't figured out the right combinations yet, but I would love to
get this fixed, if you can demonstrate how to do so, perhaps by
checking how it's set on that RHEL machine. Just:
 $ echo $EXPORT_COMMAND
 $ echo $PS1

:-Dustin

Revision history for this message
Dominic Evans (oldmanuk) wrote :

I don't think its export_command (that's blank on rhel5), and PS1 is just set for the prompt

I think its something added to the screenrc for xterm

this perhaps?

# special xterm hardstatus: use the window title.
termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen\007'

i'll attach the full screenrc for you to have a look through...

Changed in screen-profiles:
assignee: nobody → kirkland
status: New → In Progress
Changed in screen-profiles:
status: In Progress → Fix Released
Revision history for this message
Dustin Kirkland  (kirkland) wrote : Re: [Bug 338722] Re: screen-profiles does not update gnome-terminal title

Thanks for the info. I dug through the screenrc (and I want to look
through it some more), but I didn't find anything that helped.

However, I spent a few hours on this bug and found a workaround that
seems to work.

It's the $PROMPT_COMMAND that gnome-title picks up. That has to be
displayed in a bash interactive mode shell. So I added this to the
/usr/bin/screen-launcher utility:

# Ensure that the PROMPT_COMMAND gets printed, such that gnome-terminal
# and friends can pick it up before going into screen
[ -x /bin/bash ] && /bin/true | /bin/bash -i -s

That should fire up an interactive bash shell, run /bin/true, and exit
as quickly as possible.

1.33-0ubuntu1 is working well for me.

Thanks.
:-Dustin

Revision history for this message
Dominic Evans (oldmanuk) wrote :

Thanks Dustin. Amazingly fast turnaround, the fix works well for me also!

[off topic] are you not on twitter / identi.ca ?

Revision history for this message
Dominic Evans (oldmanuk) wrote :

re-opening this defect now that jaunty has shipped as I think there is more we can do

it seems on screen-profiles, we do now set the gnome-terminal title to what the machine has at screen launch (generally username@hostname: ~/) but we don't update it whilst navigating the filesystem within screen, nor do we include information about the current screen window (unlike redhat's screenrc does)

I'll add an attachment .ogv that demonstrates what redhat's screenrc does whilst in screen

Changed in screen-profiles:
status: Fix Released → New
Revision history for this message
Dominic Evans (oldmanuk) wrote :
Revision history for this message
Dominic Evans (oldmanuk) wrote :
Revision history for this message
Dustin Kirkland  (kirkland) wrote :

Okay, I'm confirming this, marking it wishlist, and assigning to Dominic.

I was able to solve the first part of the bug... Getting the host name into the gnome-terminal title.

However, getting that title to "track" what's going on inside of the screen session on a remote host isn't solved yet. I personally don't have much interest in solving this, but I'm not opposed to someone else submitting a good patch that solves this problem. Hence Confirmed/Wishlist.

Good luck,
:-Dustin

Changed in screen-profiles:
assignee: Dustin Kirkland (kirkland) → Dominic Evans (oldman)
importance: Undecided → Wishlist
status: New → Confirmed
Revision history for this message
Dominic Evans (oldmanuk) wrote :

I did some investigation on this earlier this morning and a .screenrc of

# special xterm hardstatus: use the window title.
termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen\007'
# Red Hat's normal status line
hardstatus string "[screen %n%?: %t%?] %h"

with a tweak of .bashrc to set the PROMPT_COMMAND differently under screen

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
    ;;
screen)
    PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}: ${PWD/$HOME/~}\033\\"'
    ;;
*)
    ;;
esac

emulates redhat's behaviour, basically telling screen that the terminal has its own hardstatus line in the form of its window title (termcapinfo setting), using a hardstatus string that contains %h for the current directory and using the PROMPT_COMMAND setting for screen in bashrc to keep this %h variable up to date when navigating within screen

However, as you can see, the way it works is to send all hardstatus information to the title. If you set 'alwayslastline' for the hardstatus, it is never sent to the terminal so the title remains as screen.

What we probably need is a patch for screen to allow two hardstatus lines to be set, one that is only ever sent to the terminal (that can be used as window title) and one that is only sent to screen (for when alwayslastline is set). That way screen-profiles can still continue to use the hardstatus for displaying status information etc. but we can still set the window title

Revision history for this message
Dustin Kirkland  (kirkland) wrote :

Thanks for the investigation. I'm adding a task for this bug against screen, in case we can fix it there.

I'll have a look at the screen source.

:-Dustin

Revision history for this message
Dustin Kirkland  (kirkland) wrote :

I notice that we have a very similar line in our /etc/bash.bashrc (owned by bash package), however it's commented out, with the following note:
# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.

:-Dustin

Revision history for this message
Dustin Kirkland  (kirkland) wrote :

Aha! You're absolutely right, Dominic...

  "However, as you can see, the way it works is to send all hardstatus information to the title. If you set
  'alwayslastline' for the hardstatus, it is never sent to the terminal so the title remains as screen.

  What we probably need is a patch for screen to allow two hardstatus lines to be set, one that is only ever
  sent to the terminal (that can be used as window title) and one that is only sent to screen (for when
  alwayslastline is set). That way screen-profiles can still continue to use the hardstatus for displaying status
  information etc. but we can still set the window title"

So I could get the window title to track the current directory, but it would only do so when I disabled the 'hardstatus alwayslastline' bit. Of course, that line is a huge chunk of byobu's value. I agree with you, that we need to patch screen, such that it would allow for a separation of the window title from the hardstatus.

I'm marking confirmed against screen, and invalid against byobu. If I find some time, I'll try to work on the screen patch.

Cheers,
:-Dustin

Changed in screen (Ubuntu):
importance: Undecided → Wishlist
status: New → Confirmed
Changed in byobu:
status: Confirmed → Invalid
Revision history for this message
Martin Meredith (mez) wrote :

I can change the terminal's title manually by running..

                print -Pn "\e]0;%n@%m: %~\a"

Which gets the terminals title how I want it to be, however, it doesn't track things as I go along.

Using Zsh's preexec and precmd, I can get it to change the title of the screen's window, but for some reason, the same command doesn't change the title of the window (only if I run it manually from the shell)

precmd () {
        case $TERM in
        screen-bce|screen)
                print -Pn "\e]0;%n@%m: %~\a"
                print -Pn "\ekzsh: %~\e\\"
                ;;
        xterm*|rxvt)
                print -Pn "\e]0;%n@%m: %~\a"
                ;;
        esac
}

preexec () {
        case $TERM in
        screen-bce|screen)
                print -Pn "\e]0;%n@%m: $1\a"
                print -Pn "\ek$1\e\\"
                ;;
        xterm*|rxvt)
                print -Pn "\e]0;%n@%m: $1\a"
                ;;
        esac

}

Revision history for this message
Daniel Hahler (blueyed) wrote :
Revision history for this message
SuprChrgd (cbarthel) wrote :

not for nothin, but I was playing around today with byobu 3.27 from the PPA and found that setting "hardstatus alwayslastline" affects this.

1. Set my .screenrc as suggested to mimic Redhat's screen config
2. Tested and saw that it works
3. Set "hardstatus alwayslastline" and test, watch it not work

A interesting side-effect, setting up .screenrc as suggested (or moving this into the byobu profile) is if you remove "hardstatus alwayslastline" from the byobu common profile (/usr/share/byobu/profiles/common" the hardstatus is displayed in gnome-terminal titlebar. See attached screenshot.

So I have it set up this way:
.screenrc
termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen\007'

/usr/share/byobu/profiles/common
... 1, 2, skip a few ...
#hardstatus alwayslastline
... 3, 4, skip some more ...
hardstatus string '[%n%?: %t%?] (REST OF ORIGINAL HARDSTATUS)'

Revision history for this message
Bob Will (bob-will2001) wrote :

I do not use byobu, but screen does work with window titles, even with hardstatus alwayslastline, if you surround with a DCS escape block.

Note that "hardstatus alwayslastline" intercepting the normal set title escape block is its intended purpose. The hardstatus in that case is intended to be used as a replacement title (instead of using the Window's real title).

Tthere is already a way to send escape sequences directly to the xterm, passing through screen. It was not easy to find, but from the screen code (src/ansi.c) I think its been there since 2005. I have it working in xterm, Gnome Terminal, and putty. I found a note in mintty source indicating it does not work there simply because they don't handle DCS (unless it was fixed recently).

See the documentation for screen at http://www.gnu.org/software/screen/manual/html_node/Control-Sequences.html

    ESC P (A) Device Control String
                      Outputs a string directly to the host terminal without interpretation.

The ANSI DCS (Device Control String) is an escape code that is used to send directly to a terminal (I think that was its original purpose from many years ago). Such a string is terminated with an ST escape code (String Terminator).

Wrap the string to set the terminal's window title inside a DCS..ST block, and it goes through screen and updates correctly.

This works with hardstatus alwayslastline set.

DCS = \033P
ST = \033\\

Example - to update the window title with the current working directory, use the line below. If you are in screen, even with "hardstatus alwayslastline", and ssh into a remote host and run this line, the window's title will be updated with the current dir on the remote machine.

echo -ne "\033P\033]0;${PWD/$HOME/~}\007\033\\"

Just in case I'm wrong about the screen source changes and there's something new:

I am running the latest from screen-session git, which in turn is using almost the latest from screen git (with some changes specific to screen-session). But the log messages are dated from 2005 screen (you can see the changes made to that commit regarding DCS handling if you clone the screen git repo and use the command below).
    git clone git://git.savannah.gnu.org/screen.git
    git difftool e6618a14^! src/ansi.c

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.