bce9c3bb164d60c4521ed52b2f29fb611d226649

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #404 from gwjo/ssh-agent

ssh-agent improvements

Diff

 1diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh
 2index 0efc4546f98767de768bef86e9e34169935c4c13..c4e92a1fe00403782e7eacbb0fb5009b5f65629a 100644
 3--- a/plugins/ssh-agent/ssh-agent.plugin.zsh
 4+++ b/plugins/ssh-agent/ssh-agent.plugin.zsh
 5@@ -1,23 +1,62 @@
 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+#   To load multiple identies use the identities style, For
17+#   example:
18+#
19+#     zstyle :omz:plugins:ssh-agent id_rsa id_rsa2 id_github
20+#
21+#
22+# CREDITS
23+#
24+#   Based on code from Joseph M. Reagle
25+#   http://www.cygwin.com/ml/cygwin/2001-06/msg00537.html
26+#
27+#   Agent forwarding support based on ideas from
28+#   Florent Thoumie and Jonas Pfenniger
29+#
30 
31-local SSH_ENV=$HOME/.ssh/environment-$HOST
32+local _plugin__ssh_env=$HOME/.ssh/environment-$HOST
33+local _plugin__forwarding
34 
35-function start_agent {
36-  /usr/bin/env ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
37-  chmod 600 ${SSH_ENV}
38-  . ${SSH_ENV} > /dev/null
39-  /usr/bin/ssh-add;
40+function _plugin__start_agent()
41+{
42+  local -a identities
43+
44+  # start ssh-agent and setup environment
45+  /usr/bin/env ssh-agent | sed 's/^echo/#echo/' > ${_plugin__ssh_env}
46+  chmod 600 ${_plugin__ssh_env}
47+  . ${_plugin__ssh_env} > /dev/null
48+
49+  # load identies
50+  zstyle -a :omz:plugins:ssh-agent identities identities 
51+  echo starting...
52+  /usr/bin/ssh-add $HOME/.ssh/${^identities}
53 }
54 
55-# Source SSH settings, if applicable
56+# test if agent-forwarding is enabled
57+zstyle -b :omz:plugins:ssh-agent agent-forwarding _plugin__forwarding
58+if [[ ${_plugin__forwarding} == "yes" && -n "$SSH_AUTH_SOCK" ]]; then
59+  # Add a nifty symlink for screen/tmux if agent forwarding
60+  [[ -L $SSH_AUTH_SOCK ]] || ln -sf "$SSH_AUTH_SOCK" /tmp/ssh-agent-$USER-screen
61 
62-if [ -f "${SSH_ENV}" ]; then
63-  . ${SSH_ENV} > /dev/null
64+elif [ -f "${_plugin__ssh_env}" ]; then
65+  # Source SSH settings, if applicable
66+  . ${_plugin__ssh_env} > /dev/null
67   ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
68-    start_agent;
69+    _plugin__start_agent;
70   }
71 else
72-  start_agent;
73+  _plugin__start_agent;
74 fi
75 
76+# tidy up after ourselves
77+unfunction _plugin__start_agent
78+unset _plugin__forwarding
79+unset _plugin__ssh_env
80+