Skip to content

Instantly share code, notes, and snippets.

@frippz
Last active October 22, 2015 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frippz/3088cfda93ade9dbe425 to your computer and use it in GitHub Desktop.
Save frippz/3088cfda93ade9dbe425 to your computer and use it in GitHub Desktop.
ssh-agent binding in ZSH
sshagent () {
SSHAGENT=$(ps ax|grep "[s]sh-agent"| grep -cv Z)
if (( $SSHAGENT == 0 ))
then
sshupdate
else
SSHPID="$(ps -eo pid,command | awk '/ ssh-[a]gent/ {print $1}');"
SSHPID_ENV=$(awk '/Agent/ {print $NF}' $HOME/.ssh-env)
if [[ $SSHPID == $SSHPID_ENV ]]
then
source $HOME/.ssh-env
else
killall ssh-agent
sshupdate
fi
fi
}
sshupdate () {
ssh-agent > $HOME/.ssh-env
source $HOME/.ssh-env
}
sshadd () {
if (( $(ssh-add -l | grep -c $USER) == 0 ))
then
ssh-add
else
ssh-add -l
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment