Parcourir la source

add check to ssh-agent to not run for OS X

OS X has it's own ssh-agent/keychain setup, so we only want to do this
automatically for other *nix machines.
cinaeco il y a 13 ans
Parent
commit
fb89406255
1 fichiers modifiés avec 36 ajouts et 32 suppressions
  1. 36 32
      zsh/zshrc

+ 36 - 32
zsh/zshrc

@@ -80,39 +80,43 @@ export LS_COLORS='no=00:fi=00:di=00;36:ln=01;36:pi=40;33:so=00;35:bd=40;33;01:cd
 # SSH AGENT #
 #############
 
-# Check to see if SSH Agent is already running
-agent_pid="$(ps -ef | grep "ssh-agent" | grep -v "grep" | awk '{print($2)}')"
- 
-# If the agent is not running (pid is zero length string)
-if [[ -z "$agent_pid" ]]; then
-    # Start up SSH Agent
- 
-    # this seems to be the proper method as opposed to `exec ssh-agent bash`
-    eval "$(ssh-agent)"
- 
-    # if you have a passphrase on your key file you may or may
-    # not want to add it when logging in, so comment this out
-    # if asking for the passphrase annoys you
-    #ssh-add
- 
-# If the agent is running (pid is non zero)
-else
-    # Connect to the currently running ssh-agent
- 
-    # this doesn't work because for some reason the ppid is 1 both when
-    # starting from ~/.profile and when executing as `ssh-agent bash`
-    #agent_ppid="$(ps -ef | grep "ssh-agent" | grep -v "grep" | awk '{print($3)}')"
-    agent_ppid="$(($agent_pid - 1))"
- 
-    # and the actual auth socket file name is simply numerically one less than
-    # the actual process id, regardless of what `ps -ef` reports as the ppid
-    agent_sock="$(find /tmp -path "*ssh*" -type s -iname "agent.$agent_ppid")"
- 
-    echo "Agent pid $agent_pid"
-    export SSH_AGENT_PID="$agent_pid"
+# Don't do for OSX, as it has it's own handling of ssh-agent
+if [ `uname` != Darwin ]; then
+
+  # Check to see if SSH Agent is already running
+  agent_pid="$(ps -ef | grep "ssh-agent" | grep -v "grep" | awk '{print($2)}')"
  
-    echo "Agent sock $agent_sock"
-    export SSH_AUTH_SOCK="$agent_sock"
+  # If the agent is not running (pid is zero length string)
+  if [[ -z "$agent_pid" ]]; then
+      # Start up SSH Agent
+   
+      # this seems to be the proper method as opposed to `exec ssh-agent bash`
+      eval "$(ssh-agent)"
+   
+      # if you have a passphrase on your key file you may or may
+      # not want to add it when logging in, so comment this out
+      # if asking for the passphrase annoys you
+      #ssh-add
+   
+  # If the agent is running (pid is non zero)
+  else
+      # Connect to the currently running ssh-agent
+   
+      # this doesn't work because for some reason the ppid is 1 both when
+      # starting from ~/.profile and when executing as `ssh-agent bash`
+      #agent_ppid="$(ps -ef | grep "ssh-agent" | grep -v "grep" | awk '{print($3)}')"
+      agent_ppid="$(($agent_pid - 1))"
+   
+      # and the actual auth socket file name is simply numerically one less than
+      # the actual process id, regardless of what `ps -ef` reports as the ppid
+      agent_sock="$(find /tmp -path "*ssh*" -type s -iname "agent.$agent_ppid")"
+   
+      echo "Agent pid $agent_pid"
+      export SSH_AGENT_PID="$agent_pid"
+   
+      echo "Agent sock $agent_sock"
+      export SSH_AUTH_SOCK="$agent_sock"
+  fi
 fi
 
 #############