my_ssh_agent_pid_file="~/.ssh/SSH_AGENT_PID" my_ssh_auth_sock_file="~/.ssh/SSH_AUTH_SOCK" if [[ -f "$my_ssh_agent_pid_file" && -d "/proc/$(cat "$my_ssh_agent_pid_file")" ]]; then export SSH_AGENT_PID="$(cat "$my_ssh_agent_pid_file")" export SSH_AUTH_SOCK="$(cat "$my_ssh_auth_sock_file")" else eval $(ssh-agent -s) printf '%s' "$SSH_AGENT_PID" > "$my_ssh_agent_pid_file" printf '%s' "$SSH_AUTH_SOCK" > "$my_ssh_auth_sock_file" fi