zsh:z{profile,logout}: Kill only 'own' ssh-agent

Kill the ssh-agent only if it was created in this session.

Like that the login shell can inherit SSH_AGENT_PID without it killing
the agent at the end. For this to work properly it is important that
LAUNCHED_SSH_AGENT is not exported, otherwise nested login shells will
mess with each other.
This commit is contained in:
2021-06-15 13:19:29 +02:00
parent b368b20dee
commit 57f89d34dc
2 changed files with 4 additions and 1 deletions

View File

@@ -1 +1,2 @@
[[ -z $SSH_AGENT_PID ]] || kill "$SSH_AGENT_PID"
# Kill ssh-agent if it was created in this session
! (( LAUNCHED_SSH_AGENT && SSH_AGENT_PID )) || kill "$SSH_AGENT_PID"

View File

@@ -48,6 +48,8 @@ fi
# SSH
if (( $+commands[ssh-agent] )) && [[ ! $SSH_AGENT_PID ]]; then
eval "$(ssh-agent)" >/dev/null
# See .zlogout
LAUNCHED_SSH_AGENT=1
fi
# Editor