Last active
December 15, 2015 18:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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