aboutsummaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
Diffstat (limited to 'functions')
-rw-r--r--functions/ssh.sh33
1 files changed, 33 insertions, 0 deletions
diff --git a/functions/ssh.sh b/functions/ssh.sh
new file mode 100644
index 0000000..820e787
--- /dev/null
+++ b/functions/ssh.sh
@@ -0,0 +1,33 @@
+#!/bin/zsh
+
+
+ssh-add -l &>/dev/null
+if (( ? == 2 )); then
+ # Unable to contact the authentication agent
+ # Load stored agent connection info
+ local -r ssh_env=${HOME}/.ssh-agent
+ if [[ -r ${ssh_env} ]] source ${ssh_env} >/dev/null
+
+ ssh-add -l &>/dev/null
+ if (( ? == 2 )); then
+ # Start agent and store agent connection info
+ (umask 066; ssh-agent >! ${ssh_env})
+ source ${ssh_env} >/dev/null
+ fi
+fi
+
+local ssh_bin=$(which ssh)
+auto_agent_ssh() {
+ # Load identities
+ ssh-add -l &>/dev/null
+ if (( ? == 1 )); then
+ local -a zssh_ids
+ zstyle -a ':zim:ssh' ids 'zssh_ids'
+ if (( ${#zssh_ids} )); then
+ ssh-add ${HOME}/.ssh/${^zssh_ids} 2>/dev/null
+ else
+ ssh-add 2>/dev/null
+ fi
+ fi
+ $ssh_bin "$@"
+}