How to set/change the title bar of a Terminal console in Linux?

Apr 24, 2008 at 11:02am
Hi,

How Can I change the title bar of the Terminal console in Linux?
In windows this can be done by the help of title command.
Is there anything equivalent to that?

Thanking U in Advance,
Diptendu
Apr 24, 2008 at 11:13am
Put this line in an executable shell script file:

echo -ne "\033]0;${1}\007"


(Mine is called setxtitle)

Then

setxtitle "Hello World"

sets the title of the console/terminal/xterm I ran it from to "Hello World".
Apr 30, 2008 at 11:50am
Smith Thnx for your suggestion.
But how can I use the same from c++, using system() call?

I need the same in Linux OS. For WINDOWS I am done but 4 LINUX .... :-(

1
2
3
4
5
6
7
8
9
10
11
12
void setTitle(string titleMsg)
{
#ifdef WIN32
	string title = "title ";
	title += titleMsg.c_str();
	system(title.c_str());
#else
	/*
		I want to do the above things in Linux as well.
	*/
#endif
}


Thanking U in Advance...
Diptendu
Last edited on Apr 30, 2008 at 11:50am
Apr 30, 2008 at 2:21pm
1
2
3
4
  char esc_start[] = { 0x1b, ']', '0', ';', 0 };
  char esc_end[] = { 0x07, 0 };

  cout << esc_start << "XTerm Title" << esc_end;


May 6, 2008 at 11:25am
Hi Smith,
Sorry But the above snippet of code didn't worked for me.. :-(

I have done the below in code.
1
2
3
4
5
6
7
8
9
10
11
12
void setTitle(string titleMsg)
{
#ifdef WIN32
	string title = "title ";
	title += titleMsg.c_str();
	system(title.c_str());
#else
        char esc_start[] = { 0x1b, ']', '0', ';', 0 };
        char esc_end[] = { 0x07, 0 };
        cout << esc_start <<titleMsg<< esc_end;
#endif
}


I am using Red Hat Linux 2.4.20-8smp.
Please let me know If I am doing something wrong.
May 6, 2008 at 11:59am
Sorry 'bout that. konsole seems a bit different. By default, my konsole's title bar displays "/home/jsmith - Shell - Konsole". Using my setxtitle trick, I can change it to "Foobar - Shell - Konsole". And by going to View ... Rename session I can change it to "Foobar - TurtleShell - Konsole". (I'm running FC2 / 2.6.5).

So it seems that it only partially works. It's probably doable using some X function, but I don't know anything about X programming. (Admittedly, I don't even know why the above trick works; I just saw some script do it years ago and copied the line of code).
May 8, 2008 at 1:36am
wouldn't it be the equal of
 
exec("echo -ne \"\033]0;${1}\007\" ");


But with the proper 0x0X put in. That should call that command through the console and change the title. cout << "" would only display it on screen. I don't have time atm to write the full code out sorry. But you should get the idea.
Last edited on May 8, 2008 at 1:36am
May 11, 2008 at 10:22pm
Topic archived. No new replies allowed.