1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-12-22 16:18:00 +00:00

[Fix #425] Rewrite module ssh-agent; rename it to ssh

This commit is contained in:
Sorin Ionescu 2013-05-18 19:27:40 -04:00
parent 973278140e
commit fcab2a1713
5 changed files with 79 additions and 104 deletions

View File

@ -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

View File

@ -1,62 +0,0 @@
#
# Provides for an easier use of ssh-agent.
#
# 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>
#
# 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}

28
modules/ssh/README.md Normal file
View File

@ -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

48
modules/ssh/init.zsh Normal file
View File

@ -0,0 +1,48 @@
#
# Provides for an easier use of SSH by setting up ssh-agent.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
# 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}

View File

@ -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