Created
January 27, 2014 10:42
-
-
Save ssbarnea/8646491 to your computer and use it in GitHub Desktop.
persistent-ssh
This file contains 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
# this will use screen to provide persistency when you call ssh with only the server name | |
function ssh() { | |
# DO NOT ECHO ANYTHING OR SOME PROGRAMS WILL FAIL | |
if [ "$#" == "1" ]; then | |
#echo "ssh wrapper" | |
if [ "${1:0:1}" != "-" ]; then | |
#echo "..." | |
style_term "$1" | |
#echo "Using SSH wrapper..." | |
eval last_arg=\$$# | |
/usr/bin/ssh "$@" -t ' | |
# we have to restore SSH agent | |
for key in SSH_AUTH_SOCK SSH_CONNECTION SSH_CLIENT; do | |
if (tmux show-environment | grep "^${key}" > /dev/null); then | |
value=`tmux show-environment | grep "^${key}" | sed -e "s/^[A-Z_]*=//"` | |
export ${key}="${value}" | |
fi | |
done | |
TMUX_SESS=`tmux ls|grep -m 1 -v attached|sed -e "s/:.*//"` | |
if [ "${TMUX_SESS}" = "" ]; then | |
echo "new tmux session" | |
# read -p "Press [Enter] key to..." | |
tmux || /bin/bash | |
else | |
echo tmux a -t $TMUX_SESS | |
# read -p "Press [Enter] key to..." | |
tmux a -t $TMUX_SESS | |
fi | |
' | |
#echo "Ending SSH wrapper" | |
style_term localhost | |
else | |
/usr/bin/ssh "$@"; | |
fi | |
else | |
/usr/bin/ssh "$@"; | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment