Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Provides for an easier use of GPG by setting up gpg-agent.
- #
- # Authors:
- # Sorin Ionescu <[email protected]>
- #
- # Personal modification references:
- # - https://github.com/sorin-ionescu/prezto/blob/master/modules/gpg/init.zsh
- # - https://github.com/sorin-ionescu/prezto/blob/master/modules/ssh/init.zsh
- # - https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/ssh-agent/ssh-agent.plugin.zsh
- # - https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/gpg-agent/gpg-agent.plugin.zsh
- # Return if requirements are not found.
- if (( ! $+commands[gpg-agent] )); then
- return 1
- fi
- # Set the default paths to gpg-agent files.
- _gpg_agent_conf="${GNUPGHOME:-$HOME/.gnupg}/gpg-agent.conf"
- # FIXME previously:
- # _gpg_agent_env="${TMPDIR:-/tmp}/gpg-agent.env.$UID"
- # Load environment variables from previous run
- # FIXME is this required?
- # source "$_gpg_agent_env" 2> /dev/null
- # Start gpg-agent if not started.
- # FIXME GPG_AGENT_INFO is obsolete according to `man gpg`, this was previously:
- # if [[ -z "$GPG_AGENT_INFO" && ! -S "${GNUPGHOME:-$HOME/.gnupg}/S.gpg-agent" && ! -S "/run/user/$(id -u)/gnupg/S.gpg-agent" ]]; then
- if [[ ! -S "$(gpgconf --list-dirs agent-socket)" ]]; then
- # Start gpg-agent if not started.
- # FIXME `command` was required here to avoid aliases, pattern might still need to be improved
- # FIXME is `--daemon` correct here? Arch Linux systemd socket for GPG defaults to `--supervised`
- if ! command ps -U "$LOGNAME" -o pid,ucomm | grep -q -- "${${${(s.:.)GPG_AGENT_INFO}[2]}:--1} gpg-agent"; then
- eval "$(gpg-agent --daemon | tee "$_gpg_agent_env")"
- fi
- fi
- # Inform gpg-agent of the current TTY for user prompts.
- export GPG_TTY="$(tty)"
- # Integrate with the SSH module.
- if command grep '^enable-ssh-support' "$_gpg_agent_conf" &> /dev/null; then
- # Load required functions.
- autoload -Uz add-zsh-hook
- # Override the ssh-agent environment file default path.
- # FIXME not sure what this does, but this is the reference Zinit's pmodload does not catch
- # _ssh_agent_env="$_gpg_agent_env"
- # Load the SSH module for additional processing.
- # FIXME avoid loading Prezto's SSH module for now
- # pmodload 'ssh'
- # Updates the GPG-Agent TTY before every command since SSH does not set it.
- # FIXME is this required? some places suggest `updatestartuptty`, but hooking it before every command?
- function _gpg-agent-update-tty {
- gpg-connect-agent UPDATESTARTUPTTY /bye >/dev/null
- }
- add-zsh-hook preexec _gpg-agent-update-tty
- # FIXME is this required?
- unset SSH_AGENT_PID
- export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
- fi
- # Clean up.
- unset _gpg_agent_{conf,env}
- # Disable GUI prompts inside SSH.
- if [[ -n "$SSH_CONNECTION" ]]; then
- export PINENTRY_USER_DATA='USE_CURSES=1'
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement