95a3b2768033627d9ba3e347f368dffae92906b7

Author
Joseph Benden <joe@benden.us>
Committer
Joseph Benden <joe@benden.us>
Date

Message

Add keychain plugin

This plugin integrates the Keychain tool[1] in to the project.

[1] [keychain](https://www.funtoo.org/Keychain)

Diff

 1diff --git a/plugins/keychain/README.md b/plugins/keychain/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..c603f6790055d0d5c917846c43afa2aeebfdc829
 4--- /dev/null
 5+++ b/plugins/keychain/README.md
 6@@ -0,0 +1,45 @@
 7+# keychain plugin
 8+
 9+This plugin starts automatically [`keychain`](https://www.funtoo.org/Keychain)
10+to set up and load whichever credentials you want for both gpg and ssh
11+connections.
12+
13+To enable it, add `keychain` to your plugins:
14+
15+```zsh
16+plugins=(... keychain)
17+```
18+
19+**NOTE**: It is HIGHLY recommended to also enable the `gpg-agent` plugin.
20+
21+## Instructions
22+
23+**IMPORTANT: put these settings _before_ the line that sources oh-my-zsh**
24+
25+**To adjust the agents** that keychain manages, use the `agents` style as
26+shown below. By default, only the `gpg` agent is managed.
27+
28+```zsh
29+zstyle :omz:plugins:keychain agents gpg,ssh
30+```
31+
32+To **load multiple identities** use the `identities` style, For example:
33+
34+```zsh
35+zstyle :omz:plugins:keychain identities id_ed25519 id_github 2C5879C2
36+```
37+
38+**To pass additional options** to the `keychain` program, use the
39+`options` style; for example:
40+
41+```zsh
42+zstyle :omz:plugins:keychain options --quiet
43+```
44+
45+## Credits
46+
47+Based on code from the `ssh-agent` plugin.
48+
49+## References
50+
51+- [Keychain](https://www.funtoo.org/Keychain)
52diff --git a/plugins/keychain/keychain.plugin.zsh b/plugins/keychain/keychain.plugin.zsh
53new file mode 100644
54index 0000000000000000000000000000000000000000..af34793e759e5a9feb331fd25abeac201c64c8cc
55--- /dev/null
56+++ b/plugins/keychain/keychain.plugin.zsh
57@@ -0,0 +1,32 @@
58+function _start_agent() {
59+	local agents
60+	local -a identities
61+	local -a options
62+	local _keychain_env_sh
63+	local _keychain_env_sh_gpg
64+
65+	# load agents to start.
66+	zstyle -s :omz:plugins:keychain agents agents
67+
68+	# load identities to manage.
69+	zstyle -a :omz:plugins:keychain identities identities
70+
71+	# load additional options
72+	zstyle -a :omz:plugins:keychain options options
73+
74+	# start keychain...
75+	keychain ${^options:-} --agents ${agents:-gpg} ${^identities}
76+
77+	# Get the filenames to store/lookup the environment from
78+	_keychain_env_sh="$HOME/.keychain/$SHORT_HOST-sh"
79+	_keychain_env_sh_gpg="$HOME/.keychain/$SHORT_HOST-sh-gpg"
80+
81+	# Source environment settings.
82+	[ -f "$_keychain_env_sh" ]     && . "$_keychain_env_sh"
83+	[ -f "$_keychain_env_sh_gpg" ] && . "$_keychain_env_sh_gpg"
84+}
85+
86+_start_agent
87+
88+# tidy up after ourselves
89+unfunction _start_agent