You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.8 KiB
69 lines
1.8 KiB
14 years ago
|
#
|
||
13 years ago
|
# Provides for an easier use of ssh-agent.
|
||
14 years ago
|
#
|
||
13 years ago
|
# Authors:
|
||
|
# Robby Russell <robby@planetargon.com>
|
||
|
# Theodore Robert Campbell Jr <trcjr@stupidfoot.com>
|
||
|
# Joseph M. Reagle Jr. <reagle@mit.edu>
|
||
|
# Florent Thoumie <flz@xbsd.org>
|
||
|
# Jonas Pfenniger <jonas@pfenniger.name>
|
||
|
# gwjo <gowen72@gmail.com>
|
||
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||
14 years ago
|
#
|
||
13 years ago
|
# Usage:
|
||
|
# To enable agent forwarding, add the following to your .zshrc:
|
||
14 years ago
|
#
|
||
13 years ago
|
# zstyle ':omz:module:ssh-agent' forwarding 'yes'
|
||
14 years ago
|
#
|
||
13 years ago
|
# To load multiple identities, add the following to your .zshrc:
|
||
14 years ago
|
#
|
||
13 years ago
|
# zstyle ':omz:module:ssh-agent' identities 'id_rsa' 'id_rsa2' 'id_github'
|
||
14 years ago
|
#
|
||
14 years ago
|
|
||
13 years ago
|
if (( ! $+commands[ssh-agent] )); then
|
||
13 years ago
|
return 1
|
||
13 years ago
|
fi
|
||
|
|
||
13 years ago
|
_ssh_agent_env="${HOME}/.ssh/environment-${HOST}"
|
||
14 years ago
|
_ssh_agent_forwarding=
|
||
14 years ago
|
|
||
13 years ago
|
function _ssh-agent-start {
|
||
14 years ago
|
local -a identities
|
||
|
|
||
13 years ago
|
# Start ssh-agent and setup the environment.
|
||
13 years ago
|
rm -f "${_ssh_agent_env}"
|
||
|
ssh-agent > "${_ssh_agent_env}"
|
||
14 years ago
|
chmod 600 "${_ssh_agent_env}"
|
||
13 years ago
|
source "${_ssh_agent_env}" > /dev/null
|
||
14 years ago
|
|
||
13 years ago
|
# Load identities.
|
||
13 years ago
|
zstyle -a ':omz:module:ssh-agent' identities 'identities'
|
||
13 years ago
|
|
||
13 years ago
|
if (( ${#identities} > 0 )); then
|
||
|
ssh-add "${HOME}/.ssh/${^identities[@]}"
|
||
13 years ago
|
else
|
||
13 years ago
|
ssh-add
|
||
13 years ago
|
fi
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
# Test if agent-forwarding is enabled.
|
||
13 years ago
|
zstyle -b ':omz:module:ssh-agent' forwarding '_ssh_agent_forwarding'
|
||
13 years ago
|
if is-true "${_ssh_agent_forwarding}" && [[ -n "$SSH_AUTH_SOCK" ]]; then
|
||
14 years ago
|
# Add a nifty symlink for screen/tmux if agent forwarding.
|
||
|
[[ -L "$SSH_AUTH_SOCK" ]] || ln -sf "$SSH_AUTH_SOCK" /tmp/ssh-agent-$USER-screen
|
||
|
elif [ -f "${_ssh_agent_env}" ]; then
|
||
|
# Source SSH settings, if applicable.
|
||
13 years ago
|
source "${_ssh_agent_env}" > /dev/null
|
||
13 years ago
|
ps -ef | grep "${SSH_AGENT_PID}" | grep -q 'ssh-agent$' || {
|
||
14 years ago
|
_ssh-agent-start;
|
||
14 years ago
|
}
|
||
14 years ago
|
else
|
||
14 years ago
|
_ssh-agent-start;
|
||
14 years ago
|
fi
|
||
|
|
||
14 years ago
|
# Tidy up after ourselves.
|
||
|
unfunction _ssh-agent-start
|
||
|
unset _ssh_agent_forwarding
|
||
|
unset _ssh_agent_env
|
||
14 years ago
|
|