]> git.rmz.io Git - dotfiles.git/blob - zsh/lib/gpg.zsh
aweome: open new clients as slaves
[dotfiles.git] / zsh / lib / gpg.zsh
1 #
2 # Provides for an easier use of GPG by setting up gpg-agent.
3 #
4 # Authors:
5 # Sorin Ionescu <sorin.ionescu@gmail.com>
6 #
7
8 # Return if requirements are not found.
9 if (( ! $+commands[gpg-agent] )); then
10 return 1
11 fi
12
13 # Set the default paths to gpg-agent files.
14 _gpg_agent_conf="$HOME/.gnupg/gpg-agent.conf"
15 _gpg_agent_env="${TMPDIR:-/tmp}/gpg-agent.env"
16
17 # Start gpg-agent if not started.
18 if ! ps -U "$USER" -o ucomm | grep -q gpg-agent; then
19 eval "$(gpg-agent --daemon --write-env-file "$_gpg_agent_env")"
20 else
21 # Export environment variables.
22 source "$_gpg_agent_env" 2> /dev/null
23 fi
24
25 # Inform gpg-agent of the current TTY for user prompts.
26 export GPG_TTY="$(tty)"
27
28 # Clean up.
29 unset _gpg_agent_{conf,env}
30
31 # Disable GUI prompts inside SSH.
32 if [[ -n "$SSH_CONNECTION" ]]; then
33 export PINENTRY_USER_DATA='USE_CURSES=1'
34 fi