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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
05-05-2009, 01:06 PM
|
#1
|
LQ Newbie
Registered: Apr 2009
Posts: 7
Rep:
|
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.
|
|
|
05-06-2009, 11:47 AM
|
#2
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
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.
|
|
|
05-06-2009, 01:24 PM
|
#3
|
LQ Newbie
Registered: Apr 2009
Posts: 7
Original Poster
Rep:
|
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".
|
|
|
05-06-2009, 02:28 PM
|
#4
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
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.
|
|
|
05-06-2009, 05:28 PM
|
#5
|
LQ Newbie
Registered: Apr 2009
Posts: 7
Original Poster
Rep:
|
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.
|
|
|
05-07-2009, 12:33 AM
|
#6
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
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.
|
|
|
12-02-2022, 12:39 PM
|
#7
|
LQ Newbie
Registered: Dec 2022
Posts: 1
Rep:
|
Have tried setting through PROMPT_COMMAND env variable, and it seem to work.
Set it to bashrc, and it automatically updates. Might need to source for the existing shells to update PROMPT_COMMAND.
Code:
PROMPT_COMMAND='echo -ne "\033]0;${STY}\007"'
|
|
|
All times are GMT -5. The time now is 12:20 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|