From: Alexander Barton Date: Sat, 27 Aug 2016 13:46:59 +0000 (+0200) Subject: keychanin: Enhance logic and introduce axzsh_keychain_update function X-Git-Url: https://arthur.barton.de/gitweb/?p=ax-zsh.git;a=commitdiff_plain;h=4d3ae9159b6d354187ada2ccf651bfe4248f64e6 keychanin: Enhance logic and introduce axzsh_keychain_update function Now keychain(1) is called in the "profile" stage for login shells already, to make sure that it runs before any other local scripts test, use, or update the SSH and GnuPG agents. And in addition this patch introduces the new axzsh_keychain_update function, which can be used to update the SSH and GnuPG agent information at any time. --- diff --git a/plugins/keychain/keychain.zprofile b/plugins/keychain/keychain.zprofile new file mode 100644 index 0000000..7550eec --- /dev/null +++ b/plugins/keychain/keychain.zprofile @@ -0,0 +1,7 @@ +# AX-ZSH: Alex' Modular ZSH Configuration +# keychain.zprofile: Setup keychain(1) + +# Initialize keychain(1) as soon as possible ("profile") stage, but run it +# in all sessions, in non-login shells, too. So call the "zshrc" script here +# and set a flag that keychain(1) has been initialized already. +source $(dirname "$0")/keychain.zshrc && axzsh_keychain_was_run=1 diff --git a/plugins/keychain/keychain.zshrc b/plugins/keychain/keychain.zshrc index 76b1c43..9e343ba 100644 --- a/plugins/keychain/keychain.zshrc +++ b/plugins/keychain/keychain.zshrc @@ -1,17 +1,29 @@ # AX-ZSH: Alex' Modular ZSH Configuration # keychain.zshrc: Setup keychain(1) +# Test if keychain(1) has already been initialized, for example in the +# "profile" stage. +if [[ -n "$axzsh_keychain_was_run" ]]; then + unset axzsh_keychain_was_run + return +fi + # Make sure that "keychain(1)" is installed (( $+commands[keychain] )) || return -agents="" -if (( $+commands[ssh-agent] )); then - [[ -z "$agents" ]] && agents="ssh" || agents="$agents,ssh" -fi -if (( $+commands[gpg-agent] )); then - [[ -z "$agents" ]] && agents="gpg" || agents="$agents,gpg" -fi +function axzsh_keychain_update() { + local agents + if (( $+commands[ssh-agent] )); then + [[ -z "$agents" ]] && agents="ssh" || agents="$agents,ssh" + fi + if (( $+commands[gpg-agent] )); then + [[ -z "$agents" ]] && agents="gpg" || agents="$agents,gpg" + fi + eval `keychain --agents "$agents" --eval --inherit any-once "$@"` +} -eval `keychain --agents "$agents" --eval --inherit any-once --quick --quiet` +[[ "$type" == "zshrc" ]] \ + && axzsh_keychain_update --quiet --quick \ + || axzsh_keychain_update --quiet -unset agents +unset axzsh_keychain_was_run