diff --git a/functions/__ssh_agent_is_started.fish b/functions/__ssh_agent_is_started.fish new file mode 100644 index 0000000..0a35b76 --- /dev/null +++ b/functions/__ssh_agent_is_started.fish @@ -0,0 +1,12 @@ +function __ssh_agent_is_started -d "check if ssh agent is already started" + if begin; test -f $SSH_ENV; and test -z "$SSH_AGENT_PID"; end + source $SSH_ENV > /dev/null + end + + if test -z "$SSH_AGENT_PID" + return 1 + end + + ps -ef | grep $SSH_AGENT_PID | grep -v grep | grep ssh-agent > /dev/null + return $status +end diff --git a/functions/__ssh_agent_start.fish b/functions/__ssh_agent_start.fish index 059e01f..3766fe4 100644 --- a/functions/__ssh_agent_start.fish +++ b/functions/__ssh_agent_start.fish @@ -1,4 +1,4 @@ -function __ssh_agent_start +function __ssh_agent_start -d "start a new ssh agent" ssh-agent -c | sed 's/^echo/#echo/' > $SSH_ENV chmod 600 $SSH_ENV source $SSH_ENV > /dev/null diff --git a/init.fish b/init.fish index 2f2f4cb..8f87d8a 100644 --- a/init.fish +++ b/init.fish @@ -2,12 +2,6 @@ if test -z "$SSH_ENV" setenv SSH_ENV $HOME/.ssh/environment end -if test -z "$SSH_AGENT_PID" - if test -f $SSH_ENV - source $SSH_ENV > /dev/null - end - ps -ef | grep $SSH_AGENT_PID | grep -v grep | grep ssh-agent > /dev/null - if test $status -ne 0 +if not __ssh_agent_is_started __ssh_agent_start - end end