From b60b7546809379182d95f6ab1231f060887bc067 Mon Sep 17 00:00:00 2001 From: Viktor Jackson Date: Sun, 7 Jul 2013 22:45:24 +0200 Subject: [PATCH] Create ssh module for envoy --- modules/ssh-envoy/README.md | 28 ++++++++++++++++++++++++++++ modules/ssh-envoy/init.zsh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 modules/ssh-envoy/README.md create mode 100644 modules/ssh-envoy/init.zsh diff --git a/modules/ssh-envoy/README.md b/modules/ssh-envoy/README.md new file mode 100644 index 00000000..93fccbe8 --- /dev/null +++ b/modules/ssh-envoy/README.md @@ -0,0 +1,28 @@ +SSH Envoy +========= + +Provides for an easier use of [SSH][1] by setting up [ssh-agent][2], using the [envoy][3] service for systemd. + +Settings +-------- + +### Identities + +To load multiple identities, add the following line to *zpreztorc*: + + zstyle ':prezto:module:ssh-envoy:load' identities 'id_rsa' 'id_dsa' 'id_github' + +If new identities are added while the agent is running, they will be added on your next login/source. + +Authors +------- + +*The authors of this module should be contacted via the [issue tracker][4].* + + - [Sorin Ionescu](https://github.com/sorin-ionescu) + - [Viktor Jackson](https://github.com/xlator) + +[1]: http://www.openssh.com +[2]: http://www.openbsd.org/cgi-bin/man.cgi?query=ssh-agent&sektion=1 +[3]: https://github.com/vodik/envoy +[4]: https://github.com/sorin-ionescu/prezto/issues diff --git a/modules/ssh-envoy/init.zsh b/modules/ssh-envoy/init.zsh new file mode 100644 index 00000000..33e938d6 --- /dev/null +++ b/modules/ssh-envoy/init.zsh @@ -0,0 +1,37 @@ +# +# Provides for an easier use of SSH by setting up ssh-agent via envoy (https://github.com/vodik/envoy) +# +# Authors: +# Sorin Ionescu +# Viktor Jackson +# + +# Return if requirements are not found. +if [[ "$OSTYPE" == darwin* ]] || (( ! $+commands[envoy] )); then + return 1 +fi + +# Load identities from config +zstyle -a ':prezto:module:ssh-envoy:load' identities '_ssh_identities' + +# Check if envoyd is running +if [[ `systemctl show envoy --property=ActiveState` != "ActiveState=active" ]]; then + + # Start envoy, add identities + if (( ${#_ssh_identities} > 0 )); then + /usr/bin/envoy -t ssh-agent ${^_ssh_identities[@]} + else + /usr/bin/envoy -t ssh-agent + fi + +else + for _ssh_id in $_ssh_identities + do + # Check identities and add ones that aren't already added + envoy -l | grep "$HOME/.ssh/$_ssh_id" > /dev/null + if [[ $? != 0 ]]; then + echo "New identity: $_ssh_id" + envoy -a $_ssh_id + fi + done +fi