302270174d8173be35e8c1b464a0d9e731650c15

Author
Michael Stucki <michael@stucki.io>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Use existing ssh-agent when invoking a sudo shell (#3891)

When invoking a shell as root using ```sudo -s```, the ssh-agent plugin
starts a new agent although it already exists.

The problem boils down to a check if ssh-agent is running using
```ps x```. If that is extended to ```ps ax``` for root, then the
existing ssh-agent will still work.

Diff

 1diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh
 2index 20f97c6f1718dcaad4e76b29e4d0f866cc248702..fe4946c6d0000ae8d4a57a3f2fa399e01b62a964 100644
 3--- a/plugins/ssh-agent/ssh-agent.plugin.zsh
 4+++ b/plugins/ssh-agent/ssh-agent.plugin.zsh
 5@@ -30,7 +30,12 @@ if [[ $_agent_forwarding == "yes" && -n "$SSH_AUTH_SOCK" ]]; then
 6 elif [[ -f "$_ssh_env_cache" ]]; then
 7 	# Source SSH settings, if applicable
 8 	. $_ssh_env_cache > /dev/null
 9-	ps x | grep ssh-agent | grep -q $SSH_AGENT_PID || {
10+	if [[ $USER == "root" ]]; then
11+		FILTER="ax"
12+	else
13+		FILTER="x"
14+	fi
15+	ps $FILTER | grep ssh-agent | grep -q $SSH_AGENT_PID || {
16 		_start_agent
17 	}
18 else