1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2025-07-01 10:29:25 +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

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}