brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: one printf line sets the title of your terminal tab

Terminal
~/tips/tip-terminal-printf-window-title

printf '\033]0;%s\007' "deploy running"

Names a terminal tab or window from the command line or from a script.

With six tabs open that all say zsh, finding the one running the long import is a guessing game. A short escape sequence gives the tab a real name.

Terminals understand the xterm sequence OSC 0: escape, ]0;, your text, and a bell character to end it. It sets the window and tab title.

printf '\033]0;%s\007' "deploy running"

I like it at the start of a script, so the tab tells you what is going on while you look at something else:

title() { printf '\033]0;%s\007' "$*"; }
title "backup: photos"
./backup.sh photos
title "backup done"

Put the title function in your shell config and you can call it from any prompt too. Terminal on the Mac, iTerm2, Windows Terminal and most Linux terminals all honour it.

The catch is that your shell may overwrite the title again at the next prompt. Oh My Zsh and many bash prompts set it to the current folder every time. In Oh My Zsh, DISABLE_AUTO_TITLE="true" stops that. Inside tmux the sequence goes to tmux instead, which only passes it on when set-titles is on.

Further reading: Xterm control sequences (OSC)

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link