Created
April 21, 2020 10:33
-
-
Save yasuoohno/ff119864a96db417894104162d84f75f to your computer and use it in GitHub Desktop.
fish - launch ssh-agent, if it doesn't exist
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
# | |
# 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