Browse code

Add support for loading mulitple identities

gwjo authored on 05/06/2011 at 02:16:10
Showing 1 changed files
... ...
@@ -6,6 +6,11 @@
6 6
 #
7 7
 #     zstyle :omz:plugins:ssh-agent agent-forwarding on
8 8
 #
9
+#   To load multiple identies use the identities style, For
10
+#   example:
11
+#
12
+#     zstyle :omz:plugins:ssh-agent id_rsa id_rsa2 id_github
13
+#
9 14
 #
10 15
 # CREDITS
11 16
 #
... ...
@@ -21,17 +26,23 @@ local _plugin__forwarding
21 21
 
22 22
 function _plugin__start_agent()
23 23
 {
24
+  local -a identities
25
+
26
+  # start ssh-agent and setup environment
24 27
   /usr/bin/env ssh-agent | sed 's/^echo/#echo/' > ${_plugin__ssh_env}
25 28
   chmod 600 ${_plugin__ssh_env}
26 29
   . ${_plugin__ssh_env} > /dev/null
27
-  /usr/bin/ssh-add;
30
+
31
+  # load identies
32
+  zstyle -a :omz:plugins:ssh-agent identities identities 
33
+  echo starting...
34
+  /usr/bin/ssh-add $HOME/.ssh/${^identities}
28 35
 }
29 36
 
30 37
 # test if agent-forwarding is enabled
31 38
 zstyle -b :omz:plugins:ssh-agent agent-forwarding _plugin__forwarding
32
-if [[ ${_plugin__forwarding} == "yes" && -z $SSH_AGENT_PID && -n "$SSH_AUTH_SOCK" ]]; then
33
-  # No PID but a AUTH_SOCK means agent forwarding is enabled
34
-  # Add a nifty symlink for screen/tmux 
39
+if [[ ${_plugin__forwarding} == "yes" && -n "$SSH_AUTH_SOCK" ]]; then
40
+  # Add a nifty symlink for screen/tmux if agent forwarding
35 41
   [[ -L $SSH_AUTH_SOCK ]] || ln -sf "$SSH_AUTH_SOCK" /tmp/ssh-agent-$USER-screen
36 42
 
37 43
 elif [ -f "${_plugin__ssh_env}" ]; then