Skip to content

Instantly share code, notes, and snippets.

@logic
Created February 15, 2012 18:20
Show Gist options
  • Save logic/1837945 to your computer and use it in GitHub Desktop.
Save logic/1837945 to your computer and use it in GitHub Desktop.
Teach screen and tmux about the current ssh-agent configuration
function multiplex_terminal() {
cp /dev/null $HOME/.sshvars
chmod 600 $HOME/.sshvars
for i in SSH_CLIENT SSH_TTY SSH_AUTH_SOCK SSH_CONNECTION
do
eval v="\$$i"
echo export $i=\"$v\" >> $HOME/.sshvars
done
multiplexor_path="`/usr/bin/which ${1}`"
shift
export IN_MULTIPLEXOR=yes
$multiplexor_path $*
rm -f $HOME/.sshvars
}
function ssh_connect() {
(
[ -n "$IN_MULTIPLEXOR" -a -f $HOME/.sshvars ] && . $HOME/.sshvars
ssh_path="`/usr/bin/which ${1}`"
shift
exec $ssh_path $*
)
}
alias tmux="multiplex_terminal tmux"
alias screen="multiplex_terminal screen"
alias ssh="ssh_connect ssh"
alias scp="ssh_connect scp"
alias sftp="ssh_connect sftp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment