-
-
Save bgotink/1c2f4daedb23c3f48eca to your computer and use it in GitHub Desktop.
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
set SSH_ENV $HOME/.ssh/environment | |
function start_agent | |
echo "Initializing new SSH agent ..." | |
ssh-agent -c | sed 's/^echo/#echo/' > $SSH_ENV | |
echo "succeeded" | |
chmod 600 $SSH_ENV | |
. $SSH_ENV > /dev/null | |
ssh-add | |
end | |
function test_identities | |
if ssh-add -l | grep -q "The agent has no identities" | |
ssh-add | |
if [ $status -eq 2 ] | |
start_agent | |
end | |
end | |
end | |
if [ -n "$SSH_AGENT_PID" ] | |
if ps -ef | grep $SSH_AGENT_PID | grep -q ssh-agent | |
test_identities | |
end | |
else | |
if [ -f $SSH_ENV ] | |
. $SSH_ENV > /dev/null | |
if ps -ef | grep $SSH_AGENT_PID | grep -v grep | grep -q ssh-agent | |
test_identities | |
else | |
start_agent | |
end | |
else | |
start_agent | |
end | |
end | |
# cleanup | |
functions -e start_agent | |
functions -e test_identities |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment