Now I've investigated this for the better part of a day and finally found a way to set this title. It's done via escape sequences which start with \e]0; and end with a BEL character ( = \007 = \a). Unlike I stated above, communications from the shell back to the terminal application is possible, very limited, through such escape sequences (there are a few more).
About this from above:
PROMPT_COMMAND='echo -ne "\e]0;YOUR TITLE GOES HERE\a"'
It can work, but it doesn't always.
PROMPT_COMMAND is a variable which contents is executed each time you send a command, so it also sends this escape sequence. However, this can be overriden by an escape sequence in the PS1 variable, which sets the command line prompt. This is why the above had no effect here.
From an older Ubuntu installation I grabbed this, which sets the command prompt (right part, after the
]) and also sends the required escape sequence (left part, up to and including the
PS1="\[\e]0;\u@\h: \w\a\]\u@\h:\w\$ "
This likely performs better, because there's no need to interpret
$PROMPT_COMMAND each time. It also has many more options, because Bash has more escape sequences here, e.g.
\u for the current user name,
\W for the current directory name or
\w for the entire path of the current working directory, optionally trimmed to just the last few by the number in
$PROMPT_DIRTRIM. See chapter
PROMPTING in the Bash man page. Also take note that the escape sequence has additionally to be surrounded by
To set a fixed title, this works:
PS1="\[\e]0;YOUR TITLE GOES HERE\a\]\u@\h:\w\$ "
During my investigation I also tried to understand gnome-terminal source code, which leads to vte source code and there the support for title setting and reading escape sequences is considered to be a security risk: See here (case 20, case 21) and here ("Window Title Reporting").