Skip to content

Commit

Permalink
[Fix sorin-ionescu#425] Rewrite module ssh-agent; rename it to ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
sorin-ionescu authored and Jeff Knupp committed Oct 15, 2013
1 parent 82a2cf3 commit 9767a0c
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 104 deletions.
36 changes: 0 additions & 36 deletions modules/ssh-agent/README.md

This file was deleted.

62 changes: 0 additions & 62 deletions modules/ssh-agent/init.zsh

This file was deleted.

28 changes: 28 additions & 0 deletions modules/ssh/README.md
Original file line number Diff line number Diff line change
@@ -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 changes: 48 additions & 0 deletions modules/ssh/init.zsh
Original file line number Diff line number Diff line change
@@ -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}

9 changes: 3 additions & 6 deletions runcoms/zpreztorc
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,11 @@ zstyle ':prezto:module:prompt' theme 'knupp'
# 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
Expand Down

0 comments on commit 9767a0c

Please sign in to comment.