LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 05-05-2009, 12:06 PM   #1
WindAndTiger
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Rep: Reputation: 0
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.
 
Old 05-06-2009, 10:47 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
Old 05-06-2009, 12:24 PM   #3
WindAndTiger
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Original Poster
Rep: Reputation: 0
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".
 
Old 05-06-2009, 01:28 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
Old 05-06-2009, 04:28 PM   #5
WindAndTiger
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
Old 05-06-2009, 11:33 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
  


Reply

Tags
screen, xterm


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get the title of xterm/gnome-terminal redleafong Linux - Software 6 01-10-2011 06:38 PM
gnu screen won't do 256 colors with xterm, rxvt, mrxvt slackware-elf Linux - Software 2 09-12-2007 10:47 PM
Set the Xterm title to reflect the current time ! Bonch Linux - Newbie 11 10-25-2004 04:50 PM
Blank Screen when Run-level set to 5/ Slow X Session nikhil_no_1 Fedora 0 09-16-2004 02:22 AM
How to set title in xterm according to what program running ? tvn Linux - General 1 07-25-2004 07:58 PM


All times are GMT -5. The time now is 09:20 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration