gpg-agent.plugin.zsh 736 B

123456789101112131415161718192021222324252627282930
  1. local GPG_ENV=$HOME/.gnupg/gpg-agent.env
  2. function start_agent_nossh {
  3. eval $(/usr/bin/env gpg-agent --quiet --daemon --write-env-file ${GPG_ENV} 2> /dev/null)
  4. chmod 600 ${GPG_ENV}
  5. export GPG_AGENT_INFO
  6. }
  7. function start_agent_withssh {
  8. eval $(/usr/bin/env gpg-agent --quiet --daemon --enable-ssh-support --write-env-file ${GPG_ENV} 2> /dev/null)
  9. chmod 600 ${GPG_ENV}
  10. export GPG_AGENT_INFO
  11. export SSH_AUTH_SOCK
  12. export SSH_AGENT_PID
  13. }
  14. # source settings of old agent, if applicable
  15. if [ -f "${GPG_ENV}" ]; then
  16. . ${GPG_ENV} > /dev/null
  17. fi
  18. # check for existing ssh-agent
  19. if ssh-add -l > /dev/null 2> /dev/null; then
  20. start_agent_nossh;
  21. else
  22. start_agent_withssh;
  23. fi
  24. GPG_TTY=$(tty)
  25. export GPG_TTY