Skip to content

Instantly share code, notes, and snippets.

@yasuoohno
Created April 21, 2020 10:33
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 yasuoohno/ff119864a96db417894104162d84f75f to your computer and use it in GitHub Desktop.
Save yasuoohno/ff119864a96db417894104162d84f75f to your computer and use it in GitHub Desktop.
fish - launch ssh-agent, if it doesn't exist
#
# launch-ssh-agenet
#
function __lsa_get-sshenv
if set -q SSHENV
echo $SSHENV
else
echo $HOME/.ssh/.sshenv
end
end
function __lsa_source-sshenv
set -l SSHENV (__lsa_get-sshenv)
if test -e $SSHENV
source $SSHENV > /dev/null
else
set -g SSH_AGENT_PID "NOPID"
set -g SSH_AUTH_SOCK "NOSOCK"
end
end
function __lsa_validate-sshenv
__lsa_source-sshenv
if pgrep -u $USER ssh-agent | grep -q -w $SSH_AGENT_PID
return 0
else
return 1
end
end
function launch-ssh-agent --description="Launch ssh-agent if not exists"
if not __lsa_validate-sshenv
set -l SSHENV (__lsa_get-sshenv)
ssh-agent -c > $SSHENV
end
__lsa_source-sshenv
end
launch-ssh-agent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment