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.

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay