]> arthur.barton.de Git - ax-zsh.git/blob - plugins/gnupg/gnupg.zshrc
431b16a8709f9c6a4c390a318b63062b4401d975
[ax-zsh.git] / plugins / gnupg / gnupg.zshrc
1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # gnupg.zshrc: Setup GnuPG
3
4 if (( $+commands[gpg2] )); then
5         # Use the gpg completions for gpg2, too
6         compdef gpg2=gpg
7
8         if ! (( $+commands[gpg])); then
9                 # gpg2 is available, but no gpg: alias it!
10                 alias gpg="gpg2"
11         fi
12 else
13         # Make sure that "gpg(1)" is available.
14         (( $+commands[gpg] )) || return 1
15 fi
16
17 export GPG_TTY=$(tty)
18
19 agent_info_file="$HOME/.gnupg/agent.info-${HOST}"
20
21 # Validate agent info ...
22 if [[ -n "$GPG_AGENT_INFO" ]]; then
23         gpg-agent >/dev/null 2>&1 || unset GPG_AGENT_INFO
24 fi
25
26 # Read environment file, when available and agent info not already set.
27 if [[ -z "$GPG_AGENT_INFO" && -r "$agent_info_file" ]]; then
28         source "$agent_info_file" 2>/dev/null
29         [[ -n "$GPG_AGENT_INFO" ]] && export GPG_AGENT_INFO
30 fi
31
32 # Setup GnuPG agent when installed.
33 if (( $+commands[gpg-agent] )); then
34         # Start up a new GnuPP agent, when none is running/accessible:
35         if ! gpg-agent >/dev/null 2>&1; then
36                 eval $(gpg-agent --daemon --write-env-file "$agent_info_file")
37         fi
38 fi
39
40 unset agent_info_file