diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2018-06-04 01:12:01 +0000 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2018-06-04 01:12:01 +0000 |
commit | 5930c7e44c5db64126e97716332b074f56962d2e (patch) | |
tree | 58b463feeb02cabdf17fde7449cfcac10ae005f8 /%HOME% | |
parent | .bashrc: don't export PS1 (diff) | |
download | linux-home-5930c7e44c5db64126e97716332b074f56962d2e.tar.gz linux-home-5930c7e44c5db64126e97716332b074f56962d2e.zip |
spawn_ssh_agent: save variables to ~/.ssh_agent.sh
Diffstat (limited to '')
-rw-r--r-- | %HOME%/.bash_profile | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/%HOME%/.bash_profile b/%HOME%/.bash_profile index dbdce8d..8615e60 100644 --- a/%HOME%/.bash_profile +++ b/%HOME%/.bash_profile @@ -3,12 +3,19 @@ echo "Welcome to $( hostname )" spawn_ssh_agent() { - [ -n "${SSH_AGENT_PID:+x}" ] && return 0 - - command -v ssh-agent &> /dev/null \ - && eval "$( ssh-agent -s )" > /dev/null \ - && [ -n "${SSH_AGENT_PID:+x}" ] \ - && trap "$( printf -- 'kill %q' "$SSH_AGENT_PID" )" 0 + local rm_ssh_agent + local output_path="$HOME/.ssh_agent.sh" + [ -z "${SSH_AGENT_PID:+x}" ] \ + && command -v ssh-agent > /dev/null 2>&1 \ + && touch -- "$output_path" \ + && chmod 0600 -- "$output_path" \ + && ssh-agent -s > "$output_path" \ + && source "$output_path" > /dev/null \ + && [ -n "${SSH_AGENT_PID:+x}" ] \ + && echo "Spawned ssh-agent with PID: $SSH_AGENT_PID." \ + && command -v printf > /dev/null 2>&1 \ + && rm_ssh_agent="$( printf -- 'kill %q' "$SSH_AGENT_PID" )" \ + && trap "$rm_ssh_agent" EXIT } spawn_ssh_agent |