diff --git a/modules/ssh-agent/README.md b/modules/ssh-agent/README.md deleted file mode 100644 index 392a8666fb..0000000000 --- a/modules/ssh-agent/README.md +++ /dev/null @@ -1,36 +0,0 @@ -SSH-Agent -========= - -Provides for an easier use of [ssh-agent][1]. - -Settings --------- - -### Agent Forwarding - -To enable SSH-Agent forwarding, add the following line to *zpreztorc*: - - zstyle ':prezto:module:ssh-agent' forwarding 'yes' - -### Identities - -To load multiple identities, add the following line to *zpreztorc*: - - zstyle ':prezto:module:ssh-agent' identities 'id_rsa' 'id_rsa2' 'id_github' - -Authors -------- - -*The authors of this module should be contacted via the [issue tracker][2].* - - - [Robby Russell](https://github.com/robbyrussell) - - [Theodore Robert Campbell Jr](https://github.com/trcjr) - - [Joseph M. Reagle Jr.](https://github.com/reagle) - - [Florent Thoumie](https://github.com/flz) - - [Jonas Pfenniger](https://github.com/zimbatm) - - [Gareth Owen](https://github.com/gwjo) - - [Sorin Ionescu](https://github.com/sorin-ionescu) - -[1]: http://www.openbsd.org/cgi-bin/man.cgi?query=ssh-agent&sektion=1 -[2]: https://github.com/sorin-ionescu/prezto/issues - diff --git a/modules/ssh-agent/init.zsh b/modules/ssh-agent/init.zsh deleted file mode 100644 index 56215a4f74..0000000000 --- a/modules/ssh-agent/init.zsh +++ /dev/null @@ -1,62 +0,0 @@ -# -# Provides for an easier use of ssh-agent. -# -# Authors: -# Robby Russell -# Theodore Robert Campbell Jr -# Joseph M. Reagle Jr. -# Florent Thoumie -# Jonas Pfenniger -# gwjo -# Sorin Ionescu -# - -# Return if requirements are not found. -if (( ! $+commands[ssh-agent] )); then - return 1 -fi - -# Load dependencies. -pmodload 'helper' - -_ssh_agent_env="${HOME}/.ssh/environment-${HOST}" -_ssh_agent_forwarding= - -function _ssh-agent-start { - local -a identities - - # Start ssh-agent and setup the environment. - rm -f "${_ssh_agent_env}" - ssh-agent > "${_ssh_agent_env}" - chmod 600 "${_ssh_agent_env}" - source "${_ssh_agent_env}" > /dev/null - - # Load identities. - zstyle -a ':prezto:module:ssh-agent' identities 'identities' - - if (( ${#identities} > 0 )); then - ssh-add "${HOME}/.ssh/${^identities[@]}" - else - ssh-add - fi -} - -# Test if agent-forwarding is enabled. -zstyle -b ':prezto:module:ssh-agent' forwarding '_ssh_agent_forwarding' -if is-true "${_ssh_agent_forwarding}" && [[ -n "$SSH_AUTH_SOCK" ]]; then - # 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 [[ -s "${_ssh_agent_env}" ]]; then - # Source SSH settings, if applicable. - source "${_ssh_agent_env}" > /dev/null - ps -ef | grep "${SSH_AGENT_PID}" | grep -q 'ssh-agent$' || { - _ssh-agent-start; - } -else - _ssh-agent-start; -fi - -# Tidy up after ourselves. -unfunction _ssh-agent-start -unset _ssh_agent_{env,forwarding} - diff --git a/modules/ssh/README.md b/modules/ssh/README.md new file mode 100644 index 0000000000..e953a60193 --- /dev/null +++ b/modules/ssh/README.md @@ -0,0 +1,28 @@ +SSH +=== + +Provides for an easier use of [SSH][1] by setting up [ssh-agent][2]. + +This module is disabled on Mac OS X due to custom Apple SSH support rendering it +unnecessary. + +Settings +-------- + +### Identities + +To load multiple identities, add the following line to *zpreztorc*: + + zstyle ':prezto:module:ssh:load' identities 'id_rsa' 'id_dsa' 'id_github' + +Authors +------- + +*The authors of this module should be contacted via the [issue tracker][3].* + + - [Sorin Ionescu](https://github.com/sorin-ionescu) + +[1]: http://www.openssh.com +[2]: http://www.openbsd.org/cgi-bin/man.cgi?query=ssh-agent&sektion=1 +[3]: https://github.com/sorin-ionescu/prezto/issues + diff --git a/modules/ssh/init.zsh b/modules/ssh/init.zsh new file mode 100644 index 0000000000..447846f56f --- /dev/null +++ b/modules/ssh/init.zsh @@ -0,0 +1,48 @@ +# +# Provides for an easier use of SSH by setting up ssh-agent. +# +# Authors: +# Sorin Ionescu +# + +# Return if requirements are not found. +if [[ "$OSTYPE" == darwin* ]] || (( ! $+commands[ssh-agent] )); then + return 1 +fi + +# Set the path to the SSH directory. +_ssh_dir="$HOME/.ssh" + +# Set the path to the environment file if not set by another module. +_ssh_agent_env="${_ssh_agent_env:-$TMPDIR/ssh-agent.env}" + +# Set the path to the persistent authentication socket. +_ssh_agent_sock="$TMPDIR/ssh-agent.sock" + +# Start ssh-agent if not started. +if [[ ! -S "$SSH_AUTH_SOCK" ]]; then + eval "$(ssh-agent | sed '/^echo /d' | tee "$_ssh_agent_env")" +else + # Export environment variables. + source "$_ssh_agent_env" 2> /dev/null +fi + +# Load identities. +if ssh-add -l 2>&1 | grep 'The agent has no identities'; then + zstyle -a ':prezto:module:ssh:load' identities '_ssh_identities' + if (( ${#identities} > 0 )); then + ssh-add "$_ssh_dir/${^_ssh_identities[@]}" + else + ssh-add + fi +fi + +# Create a persistent SSH authentication socket. +if [[ -S "$SSH_AUTH_SOCK" && "$SSH_AUTH_SOCK" != "$_ssh_agent_sock" ]]; then + ln -sf "$SSH_AUTH_SOCK" "$_ssh_agent_sock" + export SSH_AUTH_SOCK="$_ssh_agent_sock" +fi + +# Clean up. +unset _ssh_{dir,identities} _ssh_agent_{env,sock} + diff --git a/runcoms/zpreztorc b/runcoms/zpreztorc index 4fe15fc98d..5eca1a0d35 100644 --- a/runcoms/zpreztorc +++ b/runcoms/zpreztorc @@ -95,14 +95,11 @@ zstyle ':prezto:module:prompt' theme 'sorin' # zstyle ':prezto:module:screen' auto-start 'yes' # -# SSH-Agent +# SSH # -# Enable ssh-agent forwarding. -# zstyle ':prezto:module:ssh-agent' forwarding 'yes' - -# Set ssh-agent identities to load. -# zstyle ':prezto:module:ssh-agent' identities 'id_rsa' 'id_rsa2' 'id_github' +# Set the SSH identities to load into the agent. +# zstyle ':prezto:module:ssh:load' identities 'id_rsa' 'id_rsa2' 'id_github' # # Syntax Highlighting