LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to set xterm title to gnu screen session name (http://www.linuxquestions.org/questions/linux-software-2/how-to-set-xterm-title-to-gnu-screen-session-name-723907/)

WindAndTiger 05-05-2009 12:06 PM

How to set xterm title to gnu screen session name
 
Hello,

I usually have several xterms open, with each one running a different gnu screen session. It would be useful if--at a glance--I could see the session name in the xterm title bar. That way I would be able to quickly tell which screen sessions are running in which xterms. This would be very useful when alt-tabbing.

I know that there are termcap, terminfo, and termcapinfo commands available, but I don't know how to use these. I also know that there's an $STY environment variable that stores the session name.

Also, I do not want to lose my current "hardstatus alwayslastline" bar. It seems like this should be independent from the xterm title, anyways.

Thanks.

theNbomr 05-06-2009 10:47 AM

If you use screen to set the title, it can be done either as a screen '-t' commandline argument, or from within a screen session with the 'Ctl-A A' command to set the title.
At runtime, you can also include escape sequences in your shell prompt (bash works well for this), which get trapped by the xterm each time the prompt is printed. See How to change the title of an xterm for details.

--- rod.

WindAndTiger 05-06-2009 12:24 PM

Ah, but I specifically do not want a screen "title" as my xterm title (or any part of the prompt)--what I want is my screen *session name* as the xterm title.

E.g. a "screen -ls" might show:

1234.work (attached)
3456.play (attached)

If I had two xterms open, one running "work" and the other running "play", I would want my two xterm titles to be "work" and "play".

theNbomr 05-06-2009 01:28 PM

Well, if I start screen in an xterm thusly:
Code:

xterm -e 'screen -S Office'&
my xterm title bar contains the text within the single quotes, including, of course, the session name.

If I want, I can use the same string for the screen session name and the xterm title:
Code:

xterm -T "Office" -e 'screen -S Office'&
Doing this causes only the expected string to appear in the title bar of the xterm.

It perhaps is not immediately obvious from the link I posted, but by embedding the magic escape sequences to set your xterm title bar into your shell prompt, they do not necessarily become a visible part of the prompt. Since they are like any other escape sequence, they are trapped and handled purely within the xterm, and result in specific behavior by the xterm. The principle is the same as escape sequences that set fonts, move cursors, etc. Using such escape sequences is likely to be the only method of setting the title from within the xterm itself.

I think the essential intractable problem is that the session name cannot by queried from within the session itself.

--- rod.

WindAndTiger 05-06-2009 04:28 PM

Thanks. You've given me some useful information that I didn't know. I think we're almost there!

I don't think the xterm -T/-e solution is the best, though, since I often need to reattach an already running screen session. It may work by executing a screen reattach via -e, but it's a little clunky to have to execute a lengthy xterm command each time.

Actually, there is a way to query for the session name from within screen. The $STY environment variable, to be precise. I'm not sure if that can be used from an escape sequence, though. There must be a way!

As far as prompt escape sequences goes, question for you--is there an advantage to putting these magic escapes within the prompt versus setting them in your termcap?

Thanks.

theNbomr 05-06-2009 11:33 PM

Quote:

As far as prompt escape sequences goes, question for you--is there an advantage to putting these magic escapes within the prompt versus setting them in your termcap?
Well, mostly if they display something that changes, such as time/date, pwd, etc.

How about this, as an example:
Code:

PS1="\[\033]0; ${STY}\007\] \u@\h:\w >"
Thanks for the pointer about $STY.

--- rod.


All times are GMT -5. The time now is 03:00 AM.