]> git.rmz.io Git - dotfiles.git/blob - zsh/lib/gpg.zsh
zsh: load fzf if installed
[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 # Set the default paths to gpg-agent files.
9 _gpg_agent_conf="$XDG_CONFIG_HOME/gnupg/gpg-agent.conf"
10 _gpg_agent_env="$XDG_CACHE_HOME/gpg-agent-info"
11
12 # Return if requirements are not found.
13 if [[ ! -r "$_gpg_agent_conf" ]]; then
14 # Clean up.
15 unset _gpg_agent_{conf,env}
16 return 1
17 fi
18
19 # Start gpg-agent if not started.
20 if ! ps -U "$USER" -o ucomm | grep -q gpg-agent; then
21 eval "$(gpg-agent --daemon --write-env-file "$_gpg_agent_env")"
22 else
23 # Export environment variables.
24 source "$_gpg_agent_env" 2> /dev/null
25 fi
26
27 # Inform gpg-agent of the current TTY for user prompts.
28 export GPG_TTY="$(tty)"
29
30 # Clean up.
31 unset _gpg_agent_{conf,env}
32
33 # Disable GUI prompts inside SSH.
34 if [[ -n "$SSH_CONNECTION" ]]; then
35 export PINENTRY_USER_DATA='USE_CURSES=1'
36 fi