Wednesday, January 31, 2018

Dynamically naming Konsole tabs

So at work I use Fedora 27, and I administer quite a number of Linux servers.. So since I run the Plasma desktop environment (DE) I use the terminal emulator Konsole.  The Konsole window uses tabs.. much like modern internet browsers to help you multitask instead multiple full windows.

So anyway when you open Konsole the opening tab is named with, by default, username and current directory. If you SSH into a remote host the tab name changes to username and remote host.. which is very cool.  However if you further SSH into another host from the first the tab name remains the same as it was.  Which.. for me anyway leads to mass confusion if you have more than a couple tabs open.

So one of the fine folks in teh Fedora User mailing list tossed me a bone today.. I inquired about being able to change the tab name based on remote hostname past the first remote host.  Here's what he gave me:

    chpwd() {
        [[ -t 1 ]] || return
        case $TERM in
            sun-cmd) print -Pn "\e]l%~\e\\"
            ;;
            *xterm*|rxvt|(dt|k|E)term) print -Pn "\e]2;[%m] %~\a"
            ;;
            vt220) print -Pn "\e]2;[%m] %~\a"
            ;;
        esac
    }

    chpwd


So.. I'll admit that I do not quite understand the % or print syntax as of yet.. however adding this tidbit to the end of my .zshrc file then within Konsole changing the tab and remote tab fields to %w did exactly what I wanted to do and more.
The more part meaning that now my tab names also include the username@hostname but also the full path where I am at currently in that remote host.  Honestly its too much info for a small pane.  But it's a damned fine start!


No comments:

Post a Comment