Changing tab icons in Konsole

Today I was looking for a way to change the color of tabs in the KDE console, Konsole, to make it apparent to which remote host they are connected through SSH. This was possible in 3.5, but no longer in 4.x. However, I discovered something more awesome: it is possible to change the tab icons (small icons next to the title) using an escape sequence.

Icons can be set from a shell script with the following escape sequence:

# Icons in standard search path
echo -e "\033]32;dialog-warning\007"
echo -e "\033]32;emblem-favorite\007"

# Full path
echo -e "\033]32;/home/orion/projects/icons/fugue/icons/cookie-chocolate.png\007"

It looks like this:

The search path for icons in kubuntu is /usr/share/icons/default.kde4. It appears to be possible to use all the icons below this path, independent of category. It is also possible to specify a full path to the icon. Konsole rescales the icons to 16x16.

This gives us a way to make "favicons for SSH sites". One way to tdo this is to integrate the sequences into the shell prompt by setting the PS1 and PS2 environment variables. Or, maybe more convenient, you can set them on the host side before connecting through SSH. See this gist for an example of a script that sets per-host icons, by wrapping SSH.

With this trick, you'll never type rm -rf in the wrong console tab again...

Written on April 7, 2011
Filed under