OSC 2 Set Window Title
Set the title of the terminal's window or tab.
OSC Ps ; Pt ST
- ECMA-48
- §8.3.89 OSC – Operating System Command, p. 51
- VT510
- 4.2 Control Characters
- xterm
- Operating System Commands
Set the window title to Pt, which is UTF-8 text. Ps says which title:
Ps | Sets |
|---|---|
0 | the window title and the icon name |
1 | the icon name only |
2 | the window title only |
Nothing on the screen changes. The sequence can end with ST (ESC \) or, as most programs that set titles do, with BEL.
A shell sets this from its prompt, which is how a tab comes to show the directory you are in or the command that is running.
The older forms. Before these, Sun’s terminals and CDE’s dtterm set the title with a letter instead of a number, and xterm accepts them too: its Control Sequences document lists them in its table of the Sun and dtterm window operations.
| Sequence | Sets |
|---|---|
OSC l Pt ST | the window title |
OSC L Pt ST | the icon name |
OSC I Pt ST | the icon, from the file Pt |
There is no ;: everything after the letter is the text, a ; included (do_osc). These are also the forms xterm answers in when it reports the title or the icon name, CSI 21 t and CSI 20 t (see XTWINOPS), though a default xterm refuses those reports. libghostty-vt has only the numbered forms and ignores the letters, so the cases that set the title with OSC l are known differences.
Validation
OSC2-1: Ended with ST
\e]2;Hello\e\\
|___|
title "Hello"
cursor 1,1
OSC2-2: Ended with BEL
\e]2;Hello\a
|___|
title "Hello"
OSC2-3: OSC 0, with UTF-8
\e]0;café ☕\a
|___|
title "café ☕"
OSC2-4: The last one wins
\e]2;first\a
\e]2;second\a
|___|
title "second"
OSC2-5: The dtterm form
\e]lHello\e\\
|___|
title "Hello"
OSC2-6: Everything after the l is the title
\e]l;two;parts
|___|
title ";two;parts"
OSC2-7: OSC L sets only the icon name
\e]2;Window
\e]LIcon
\e]IIcon.xpm
A
|A__|
title "Window"
cursor 1,2