35b879a17b965b0ea28009c4561962c9ed17ef1f

Author
gwjo <gowen72@gmail.com>
Committer
gwjo <gowen72@gmail.com>
Date

Message

Add support for agent forwarding

Diff

 1diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh
 2index 0efc4546f98767de768bef86e9e34169935c4c13..0f5b03d26fa5312f710d3eba16cbc7bbd1dfbdff 100644
 3--- a/plugins/ssh-agent/ssh-agent.plugin.zsh
 4+++ b/plugins/ssh-agent/ssh-agent.plugin.zsh
 5@@ -1,23 +1,51 @@
 6-# Based on code from Joseph M. Reagle
 7-# http://www.cygwin.com/ml/cygwin/2001-06/msg00537.html
 8+#
 9+# INSTRUCTIONS
10+#
11+#   To enabled agent forwarding support add the following to
12+#   your .zshrc file:
13+#
14+#     zstyle :omz:plugins:ssh-agent agent-forwarding on
15+#
16+#
17+# CREDITS
18+#
19+#   Based on code from Joseph M. Reagle
20+#   http://www.cygwin.com/ml/cygwin/2001-06/msg00537.html
21+#
22+#   Agent forwarding support based on ideas from
23+#   Florent Thoumie and Jonas Pfenniger
24+#
25 
26-local SSH_ENV=$HOME/.ssh/environment-$HOST
27+local _plugin__ssh_env=$HOME/.ssh/environment-$HOST
28+local _plugin__forwarding
29 
30-function start_agent {
31-  /usr/bin/env ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
32-  chmod 600 ${SSH_ENV}
33-  . ${SSH_ENV} > /dev/null
34+function _plugin__start_agent()
35+{
36+  /usr/bin/env ssh-agent | sed 's/^echo/#echo/' > ${_plugin__ssh_env}
37+  chmod 600 ${_plugin__ssh_env}
38+  . ${_plugin__ssh_env} > /dev/null
39   /usr/bin/ssh-add;
40 }
41 
42-# Source SSH settings, if applicable
43+# test if agent-forwarding is enabled
44+zstyle -b :omz:plugins:ssh-agent agent-forwarding _plugin__forwarding
45+if [[ ${_plugin__forwarding} == "yes" && -z $SSH_AGENT_PID && -n "$SSH_AUTH_SOCK" ]]; then
46+  # No PID but a AUTH_SOCK means agent forwarding is enabled
47+  # Add a nifty symlink for screen/tmux 
48+  [[ -L $SSH_AUTH_SOCK ]] || ln -sf "$SSH_AUTH_SOCK" /tmp/ssh-agent-$USER-screen
49 
50-if [ -f "${SSH_ENV}" ]; then
51-  . ${SSH_ENV} > /dev/null
52+elif [ -f "${_plugin__ssh_env}" ]; then
53+  # Source SSH settings, if applicable
54+  . ${_plugin__ssh_env} > /dev/null
55   ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
56-    start_agent;
57+    _plugin__start_agent;
58   }
59 else
60-  start_agent;
61+  _plugin__start_agent;
62 fi
63 
64+# tidy up after ourselves
65+unfunction _plugin__start_agent
66+unset _plugin__forwarding
67+unset _plugin__ssh_env
68+