diff --git a/plugins/keychain/keychain.plugin.zsh b/plugins/keychain/keychain.plugin.zsh new file mode 100644 index 000000000..3edf376a4 --- /dev/null +++ b/plugins/keychain/keychain.plugin.zsh @@ -0,0 +1,37 @@ +local ssh_env=$HOME/.ssh/environment-$HOST + +function start_agent() +{ + local -a identities + + # start ssh-agent and setup environment + ssh-agent | sed 's/^echo/#echo/' >${ssh_env} + chmod 600 $ssh_env + source $ssh_env >/dev/null + + # load identies + zstyle -a :omz:plugins:ssh-agent identities identities + ssh-add $HOME/.ssh/${^identities} +} + +function keychain() { + case $1 in + "start") ;; + "kill") + ssh-agent -k + ;; + esac +} + +zstyle -a :omz:plugins:keychain autostart state +if [[ $state == "on" ]]; then + if [[ -f $ssh_env ]]; then + source $ssh_env >/dev/null + ps -p $SSH_AGENT_PID >/dev/null || start_agent + else + start_agent; + fi +fi + +unfunction start_agent +unset ssh_env diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh deleted file mode 100644 index 40d78ca26..000000000 --- a/plugins/ssh-agent/ssh-agent.plugin.zsh +++ /dev/null @@ -1,33 +0,0 @@ -local ssh_env=$HOME/.ssh/environment-$HOST -# local state - -function start_agent() -{ - local -a identities - - # start ssh-agent and setup environment - ssh-agent | sed 's/^echo/#echo/' >${ssh_env} - chmod 600 $ssh_env - source $ssh_env >/dev/null - - # load identies - zstyle -a :omz:plugins:ssh-agent identities identities - ssh-add $HOME/.ssh/${^identities} -} - -# test if agent-forwarding is enabled -# zstyle -b :omz:plugins:ssh-agent agent-forwarding state - -# if [[ $state == "yes" && -n "$SSH_AUTH_SOCK" ]]; then -# [[ -L $SSH_AUTH_SOCK ]] || ln -sf $SSH_AUTH_SOCK /tmp/ssh-agent-$USER-screen -if [[ -f $ssh_env ]]; then - source $ssh_env >/dev/null - ps -p $SSH_AGENT_PID >/dev/null || start_agent -else - start_agent; -fi - -# tidy up after ourselves -unfunction start_agent -# unset state -unset ssh_env