Skip to content

Instantly share code, notes, and snippets.

@jdsumsion
Forked from Jwpe/ssh_agent_start.fish
Last active August 29, 2015 14:05
Show Gist options
  • Save jdsumsion/2ad56c8c4cdd19dcfd86 to your computer and use it in GitHub Desktop.
Save jdsumsion/2ad56c8c4cdd19dcfd86 to your computer and use it in GitHub Desktop.
function ssh-agent-launch
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 ssh-agent-test
ssh-add -l | grep "The agent has no identities" > /dev/null
if [ $status -eq 0 ]
ssh-add
if [ $status -eq 2 ]
ssh-agent-launch
end
else
true
end
end
function ssh-agent-start
setenv SSH_ENV $HOME/.ssh/environment
if [ -n "$SSH_AGENT_PID" ]
ps -ef | grep $SSH_AGENT_PID | grep ssh-agent > /dev/null
if [ $status -eq 0 ]
ssh-agent-test
end
else
if [ -f $SSH_ENV ]
. $SSH_ENV > /dev/null
end
ps -ef | grep $SSH_AGENT_PID | grep -v grep | grep ssh-agent > /dev/null
if [ $status -eq 0 ]
ssh-agent-test
else
ssh-agent-launch
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment