diff --git a/functions.sh b/functions.sh index 8adcd86..1e4c68d 100755 --- a/functions.sh +++ b/functions.sh @@ -836,7 +836,7 @@ token-list-objects() { } -loadagent () { +ssh-loadagent () { # TODO: create agent if not running cat << EOF @@ -844,15 +844,27 @@ loadagent () { SSH_AGENT_PID: ${SSH_AGENT_PID} --------------------------------------------- EOF - ssh_identity=$1 + ssh_identity=${1-default} + agentfile="${HOME}/.ssh/agents/agent-${ssh_identity}-$(hostname)" + echo agentfile: $agentfile if [ -n "${ssh_identity+x}" ]; then - agentfile="${HOME}/.ssh/agents/agent-${ssh_identity}-$(hostname)" if [ -e "$agentfile" ]; then . $agentfile + if ssh-add -l >/dev/null ;then + echo agent is running + else + echo create new agent + ssh-agent > "$agentfile" + fi + else + echo create new agent + ssh-agent > "$agentfile" fi fi + eval $(<$agentfile) + cat << EOF SSH_AUTH_SOCK: ${SSH_AUTH_SOCK} SSH_AGENT_PID: ${SSH_AGENT_PID}