Automatically rename KONSOLE tab during telnet or ssh.

Posted on June 6, 2008 by ZDima.
Categories: Development, UNIX, UNIX-Shell.

I am using KDE konsole as my primary terminal interface.

To keep tab organized I am using wrapper script for telnet and ssh where I am calling dcop to change the tab name with a with a host name:

#!/bin/sh

telnet_log=/tmp/telnet.log.$$

restore_title()
{
	if [ "${OLD_TITLE}x" != "x" ]
	then
		dcop "$KONSOLE_DCOP_SESSION" renameSession "$OLD_TITLE"
		OLD_TITLE=
	fi
}

change_title()
{
	if [ ! -z "$KONSOLE_DCOP_SESSION" ]
	then
		OLD_TITLE=`dcop "$KONSOLE_DCOP_SESSION" sessionName`
		dcop "$KONSOLE_DCOP_SESSION" renameSession "$NEW_TITLE"
	fi
}

handle_quit_intr()
{
	restore_title
}

trap handle_quit_intr SIGINT INT QUIT

for arg in $@
do
	NEW_TITLE="$arg"
done

OLD_TITLE=
export OLD_TITLE
export NEW_TITLE

change_title
/usr/bin/telnet $* 2> $telnet_log
rc=$?
restore_title
echo "telnet exit with code $rc"

if [ $rc -eq 0 ]
then
	[ -f $telnet_log ] && rm -f $telnet_log
	exit 0
fi
exit $rc

no comments yet.

Leave a comment

Names and email addresses are required (email addresses aren't displayed), url's are optional.

Comments may contain the following xhtml tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>