gpg-agent.plugin.zsh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. # check if another agent is running
  15. if ! gpg-connect-agent --quiet /bye > /dev/null 2> /dev/null; then
  16. # source settings of old agent, if applicable
  17. if [ -f "${GPG_ENV}" ]; then
  18. . ${GPG_ENV} > /dev/null
  19. fi
  20. # check again if another agent is running using the newly sourced settings
  21. if ! gpg-connect-agent --quiet /bye > /dev/null 2> /dev/null; then
  22. # check for existing ssh-agent
  23. if ssh-add -l > /dev/null 2> /dev/null; then
  24. # ssh-agent running, start gpg-agent without ssh support
  25. start_agent_nossh;
  26. else
  27. # otherwise start gpg-agent with ssh support
  28. start_agent_withssh;
  29. fi
  30. fi
  31. fi
  32. GPG_TTY=$(tty)
  33. export GPG_TTY