From time to time I get badly confused about which terminal window does what. This is on a Pi5 running bookworm, if it matters.
One thing that would help is causing each lxterminl window or tab to display the name of the command being run. In most cases that would be an ssh command and hostname.
Obviously, this can be done manually by using the Tabs > Name Tab menuu, but it seems likely there'd be a setting in .config/lxterminal/lxterminal.conf which I'm unable to intuit.
Does anyone know if this is true, and if so what syntax is required?
Thanks for reading,
bob prohaska
Didn't find your answer? Ask the community — no account required.
J
Jim Jackson
You need to write the string ESC]0;Title^G to the terminal.
I have this in a little script called xtn which does this.
To generate ESC in bash use ^V^[ where '^' is holding down the control key. ^G is done like wise. You will have to wrap the strings in quotes
e.g. echo -n "^[]0;"$1"^G"
good luck. I've just done this in LXTerminal with bash as my shell.
bash should set the window title to the current command, using the same escape sequence. If it doesn't:
a) you aren't using bash. Maybe it needs to be enabled in your shell?
b) bash is not configured to set the title, I'm not sure where you'd find that
c) your terminal is not advertising itself as a suitable type that uses the escape code. What's your TERM variable set to?
d) your terminal is choosing not to display it, for some reason (perhaps the configuration you mention above)
Theo
B
bp
It doesn't seem to do much of anything in my case. Here's a transcript: bob@raspberrypi:~$ echo $TERM xterm-256color bob@raspberrypi:~$ echo -n "^[]0;"$1"^G" ^[]0;^Gbob@raspberrypi:~$ bob@raspberrypi:~$
I was hoping to see the title change, but no luck. As you might guess, my fluency with shells is abysmal. I use them only in a very simple-minded way, usually to type single commands.
Thanks for writing!
bob prohaska
B
bp
No. Neither does it trigger an error message....
According to /etc/passwd, bash is my login shell, running bob@raspberrypi:~$ echo $TERM xterm-256color
suggests that lxterm is a variant of xterm, which makes sense.
As above, xterm-256color
The configuration file at ~/.config/lxterminal/lxterminal.conf contains quite a few entries, but none appears to be related to titles. The man page for lxterminal doesn't give any useful hints. The config file appears to be name=value format, Shift-ctrl-I brings up the dialog to manually enter a title which is interpreted as a simple string.
Thanks for writing!
bob prohaska
R
Richard Harnden
Does
echo -en "\033]0;Hello World\007"
work?
G
Gordon Henderson
This is on "generic Linux" if it matters:
In ~/bin I have an executable script:
#!/bin/sh
if [ "x$*" = x ]; then echo -n "\033];`hostname`\007" else echo -n "\033];$*\007" fi
I call it 'xtt' (xterm title - works in xterm and other terminals I use) You make it yours and call it what you like.
So xtt on it's own resets the title to your hostname (handy if you login to many systems) othrwise it sets the title to whatever you put on the command line
xtt silly editing session
for example
Your challenge is to make it work automatically for every command you type.. (I don't need that functionality, I use it inside other scripts that start stuff)
Gordon
J
Jim Jackson
Did you type '^' then '['? Instead you should type ctl-V Ctl-[ and the same for for the other control character.
It worked for me in lxterminal and the $TERM was identical to yours.
so no output beyond the echoed input and no change in the tab title. I rather wonder where the command output went, since no error was reported.
If I'm missing something idiotic please point it out!
Thanks for writing,
bob prohaska
J
Jim Jackson
Bravo. The simplest solution - all "normal" characters.
B
bp
This suggestion might touch on a fundamental issue: Which host, the ssh client or the ssh server, gets to set the window or tab title on the client machine running RasPiOS? I've been thinking it's the RasPiOS machine displaying the window or tab. If I'm understanding you correctly it's the server end of the connection. Is that correct?
I'm working with only one RasPiOS workstation client and several FreeBSD servers. I'd rather customize the workstation than the servers, if that's possible.
Thanks for writing!
bob prohaska
R
Richard Harnden
Does your PS1 keep overwritting the window title? Does the window title change if you, say, change directory?
G
Gordon Henderson
It's whatever you want it to be. In my case it's the client - which to avoid ambiguity is the system I type the ssh command on...
Well... `hostname` returns the name of the host the script is running on.
One way I use it is in scripts that ssh to remote systems, so rather than type ssh frotz, I type 'frotz' which is a script in my ~/bin directory and that script looks like:
This sets the title of the xterm I'm typing into to '-> Frotz' then runs the ssh to the server...
When the ssh exits (ie. I logout of Frotz), the xtt command with no arguments resets the terminal title bar to that on whatever host I typed the command at. (either my desktop or laptop)
Gordon
T
Theo
To expand on that, all this \033]; stuff are 'terminal escape sequences'. They cause the app which is displaying the data stream from your terminal to set the 'window title', whatever that means in its context (typically the tab title in a tabbed terminal window), to the string embedded in the escape sequence.
Because they're just bytes, they can be passed over an SSH connection just like any other bytes (letters, text colour-changes, cursor movements, etc). It's then up to the receiver (the terminal app) to interpret them.
The other piece of the puzzle is that your terminal needs to be configured for the same 'terminal escape sequence' language. There are many kinds of terminals which speak different languages, described in /etc/termcap and related files.
You (Bob) have TERM set to 'xterm-256color' which means that it's expecting terminal messages in that language. It sounds the right one to interpret them: xterm is an X11 app where the concept of 'window title' makes sense - older terminal types like 'vt100' probably don't understand them (VT100s just had a keyboard and CRT screen - no windowing system).
Anyhow, I installed lxterminal (on Ubuntu 25.10) and I found I had the same problem. However this:
echo -e "\033]0;Hello\007" && sleep 3
does set the terminal title for 3 seconds and then it reverts to the standard. Which suggests it's the prompt that's setting it back.
I realize that the conversation has moved on, but for anyone coming in late...
There is a '3' in the above line which should not be there.
Try $ echo -en "\e]0;$TITLE\a"
Jim
J
Jim Diamond
Bob,
bp mentioned that he was using a script, and in his script $1 would be the first argument to the script.
You were just typing that from the command line, where $1 is not what you want.
As has been pointed out (and "bravo"ed), there are less error-prone ways to get the escape char out of the echo command, but assuming you know that to get ^[ you want to type Ctrl-V Escape and that to get ^G you want to type Ctrl-V Ctrl-G then putting something useful in for $1 above might help:
echo -n "^[]0;Hello There^G"
Finally, if something in your default setup is resetting the tab/terminal title to something else every time before the prompt is printed, try
echo -n "^[]0;Hello There^G" ; sleep 10
and see if you see "Hello There" for 10 seconds (+/-) after you hit Enter.
Cheers. Jim
T
Theo
They both work for me (in Konsole). According to: $ zless /usr/share/doc/xterm/ctlseqs.txt.gz
Code | Sun | CDE | XTerm | Description OSC 0 ST | - | yes | yes | set window and icon title OSC 1 ST | - | yes | yes | set icon label OSC 2 ST | - | yes | yes | set window title OSC 3 ST | - | n/a | yes | set X server property
where OSC ('operating system command') is 'ESC ]' in 7-bit mode (0x9b in
8-bit mode) and ST ('sequence terminator') is 'ESC ' or 0x9c. So it looks like the first 3 is overridden by the second 0 as there's no OSC 3 0 ST command listed.
Theo
B
bp
Looks like I was mistaken. A simple copy and paste of the lineabove changes the tab title to Hello World.
I'm not sure what's different now, it's the same Pi, just a newly-created tab.
I'm also not sure I got the quotes right, apologies if things are now mis-attributed.
It seems the remaining puzzle is how to replace the string Hello World with the name of the last-typed command...
Thanks for writing!
bob prohaska
R
Richard Harnden
I think this works ...
ESC=$(echo -en "\033") BEL=$(echo -en "\007")
export HISTFILE=~./bash_history$(tty | sed "s,/,_,g")
I really owe everybody an apology here. I thought there'd be some trivial way to auto-title lxterminal windows so they could be easily distinguished. Clearly there isn't such a thing. The "name tab" option takes only a few seconds and is probably the most efficient way to keep folks like me from typing the wrong commands in the wrong window....
Thanks for everybody's help and patience!
bob prohaska
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.