]> arthur.barton.de Git - ax-zsh.git/commitdiff
keychanin: Enhance logic and introduce axzsh_keychain_update function
authorAlexander Barton <alex@barton.de>
Sat, 27 Aug 2016 13:46:59 +0000 (15:46 +0200)
committerAlexander Barton <alex@barton.de>
Sat, 27 Aug 2016 13:46:59 +0000 (15:46 +0200)
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.

plugins/keychain/keychain.zprofile [new file with mode: 0644]
plugins/keychain/keychain.zshrc

diff --git a/plugins/keychain/keychain.zprofile b/plugins/keychain/keychain.zprofile
new file mode 100644 (file)
index 0000000..7550eec
--- /dev/null
@@ -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
index 76b1c43e30a6b3d556dc42ed35f603b09e0d9d95..9e343baa9872a39b548ddbd1937eb01e33a7db03 100644 (file)
@@ -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