Skip to content

Instantly share code, notes, and snippets.

@mondalaci
Last active December 15, 2015 18:49
Show Gist options
  • Save mondalaci/5306865 to your computer and use it in GitHub Desktop.
Save mondalaci/5306865 to your computer and use it in GitHub Desktop.
SSH wrapper script to make Konsole tab names always reflect the hostname of the current host
#!/bin/bash
# This script makes Konsole tab names always reflect the hostname of the current host.
#
# You're supposed to rename this script as "ssh" and put it into a
# directory that precedes /usr/bin in your $PATH, like /usr/local/bin
if [ "x$KONSOLE_DCOP_SESSION" = "x" ]; then
exec ssh $*
fi
function restore_old_session_name {
dcop $KONSOLE_DCOP_SESSION renameSession "$old_session_name"
}
if [ "x$KONSOLE_DCOP_SESSION" != "x" ]; then
old_session_name=`dcop $KONSOLE_DCOP_SESSION sessionName`
hostname="${!#}" # we expect the last arg to ssh to be the hostname
fi
trap "restore_old_session_name" SIGINT SIGTERM
if [ "x$KONSOLE_DCOP_SESSION" != "x" ]; then
if [ "x$hostname" != "xecho FISH:; /bin/sh" ]; then
dcop $KONSOLE_DCOP_SESSION renameSession "$hostname"
fi
fi
/usr/bin/ssh $*
if [ "x$KONSOLE_DCOP_SESSION" != "x" ]; then
restore_old_session_name
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment