7692881d2a61a4ba47eeef5d7827c0d2cb896def
Author Marc Cornellà <hello@mcornella.com> Committer Marc Cornellà <hello@mcornella.com> Date 2021-08-26 12:54 UTC
Message feat(ssh-agent): only start ssh-agent once (#5359)
Close #5359
Close #7379
Co-authored-by: Will Andrews <will@firepipe.net>
Co-authored-by: zhangyc <zhangyc@fenbi.com>
Diff 1 diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh
2 index 9bc2e8a21a84db59cf756495ae0a9ec1922ec9e9..acad4e83e7473a30693eea0b3734e97a087fafea 100644
3 --- a/plugins/ssh-agent/ssh-agent.plugin.zsh
4 +++ b/plugins/ssh-agent/ssh-agent.plugin.zsh
5 @@ -1,5 +1,3 @@
6 -typeset _agent_forwarding _ssh_env_cache
7 -
8 function _start_agent() {
9 local lifetime
10 zstyle -s :omz:plugins:ssh-agent lifetime lifetime
11 @@ -97,7 +95,23 @@ else
12 _start_agent
13 fi
14
15 -_add_identities
16 +() {
17 + emulate -L zsh
18 +
19 + command mkdir "$ZSH_CACHE_DIR/ssh-agent.lock" 2>/dev/null || return
20 +
21 + trap "
22 + ret=\$?
23 +
24 + command rm -rf '$ZSH_CACHE_DIR/ssh-agent.lock'
25 + unset _agent_forwarding _ssh_env_cache
26 + unfunction _start_agent _add_identities 2>/dev/null
27 +
28 + return \$ret
29 + " EXIT INT QUIT
30 +
31 + _add_identities
32 +}
33
34 # tidy up after ourselves
35 unset _agent_forwarding _ssh_env_cache