Bash – How to one set a terminal’s title with the ‘tput’ command

bashbashrcshellterminalterminfo

I discovered through this answer that I've been setting terminal colours in my prompt in a naive way for years.

I've now modified my .bashrc to use 'tput' commands to colourise various elements of my prompt. The one remaining escape code I have is this:

TITLEBAR="\[\033]2; PROD - \u@\h:\w \007\]"

Does anyone know if there is a tput/terminfo attribute I can use to set the title bar of my terminal window, so that I can eliminate that escape?

Best Answer

The actual capabilities are tsl (To Status Line) and fsl (From Status Line), but of course not all terminals have then. In Linux in particular you need to set your terminal to xterm+sl or something similar.

You can test this with

export TERM=xterm+sl
echo `tput tsl` Hello world `tput fsl`; sleep 10

I wouldn't bother and keep those escapes in .bashrc