DEV Community

mdh81
mdh81

Posted on

3 2

Tab/window management with titles

Do you get lost managing multiple tabs or windows in your terminal emulator? If so, this trick might be handy to your shell toolbox.

Define a function like this in your shell profile

function title {
    echo -ne "\033]0;"$*"\007"
}
Enter fullscreen mode Exit fullscreen mode

And then when you open your all important terminal window or tab, call the function and pass a string to it like so:

$ title <title string>
Enter fullscreen mode Exit fullscreen mode

Viola, you have a handy way of identifying your terminal window/tab and not be lost in a forest of tabs or windows.

Isn't this neat?

Image description

Now, let's explain this function a bit. echo needs no introduction. -n stands tells echo not to print a new-line after the message. -etells echo to interpret escape sequences.

The trick that makes this work is the text flanked by xterm escape sequences and sequences themselves.

\033 Escape
\077 Bell
]0; Identifier for window title and icon
"$*" String that contains all arguments passed to echo

Most terminal emulators support these xterm sequences. I tested in iterm and it works beautifully. Go ahead, try it out and help yourself navigate the terminal tab/window maze.

References:

https://tldp.org/HOWTO/Xterm-Title-3.html
Stackoverflow threads on this topic.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more