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?


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

  • 1
    Seems my copy of Ubuntu lacks that terminal info. :( I blame incomplete terminfo files :) Jun 11 '09 at 12:16
  • 1
    screen, however, appaears to support them just fine. Thanks! Jun 11 '09 at 12:26
  • 3
    \033]; is the escape sequence in xterm for an "Operating System Command". I don't know how to do that in tput, but if it is possible to do via tput that would be a better method for cross platform terminal title setting. E.g. on xterm, it would result in the sequence \033]0;Title\007. See also here
    – Wyatt Ward
    Mar 23 '18 at 17:09
  • @codehead Your solution is embarrassing because if I type export TERM=xterm+sl, then I no longer have syntax highting in vim.
    – SebMa
    Apr 26 '19 at 13:49

Having looked at the xterm terminfo file, I can't find any code that is identical to this command, so I suspect there is not.

If you're interested, the terminfo man page lists all the commands that termcap and terminfo understand. I decompiled the terminfo database file using:

# infocmp -L xterm 

I can't comment, thus an extra answer:

If you use tsl/fsl, be sure to ask the terminal for hs first. hs should be true if tsl/fsl (and other *sl) are supported.

tput hs && { echo ....; }
  • 1
    +1 if you have a reference for this.
    – l0b0
    Mar 21 '12 at 8:28
  • @l0b0 - I guess it could be inferred from man 5 terminfo, specifically the Status Lines section. See: man7.org/linux/man-pages/man5/terminfo.5.html Of course, I guess you could also do: tput tsl && { echo 'hello world'; tput fsl; }
    – mpb
    Jun 20 '20 at 23:37
  • @mpb tput tsl and tput hs both fail in GNOME Terminal, so I'm not sure what to do with either.
    – l0b0
    Jun 21 '20 at 2:47
  • @l0b0 - It does seem that multiple terminals do support changing the title, but this feature is not published in their terminfo entries. If you are programming conservatively, and you are writing an app that may be used across multiple terminals by third-party users, then the safe thing to do would be to check that tsl (or hs) existed. If you assume it exists, and it does not, then you would end up writing unintended text at the cursor location.
    – mpb
    Jun 21 '20 at 5:29

For more info on xterm's "vt100 mode" special features, see the Xterm Control Sequences document in the Operating System Controls section for all the gory details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.