keychain.plugin.zsh 962 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Define SHORT_HOST if not defined (%m = host name up to first .)
  2. SHORT_HOST=${SHORT_HOST:-${(%):-%m}}
  3. function _start_agent() {
  4. local agents
  5. local -a identities
  6. local -a options
  7. local _keychain_env_sh
  8. local _keychain_env_sh_gpg
  9. # load agents to start.
  10. zstyle -s :omz:plugins:keychain agents agents
  11. # load identities to manage.
  12. zstyle -a :omz:plugins:keychain identities identities
  13. # load additional options
  14. zstyle -a :omz:plugins:keychain options options
  15. # start keychain...
  16. keychain ${^options:-} --agents ${agents:-gpg} ${^identities} --host $SHORT_HOST
  17. # Get the filenames to store/lookup the environment from
  18. _keychain_env_sh="$HOME/.keychain/$SHORT_HOST-sh"
  19. _keychain_env_sh_gpg="$HOME/.keychain/$SHORT_HOST-sh-gpg"
  20. # Source environment settings.
  21. [ -f "$_keychain_env_sh" ] && . "$_keychain_env_sh"
  22. [ -f "$_keychain_env_sh_gpg" ] && . "$_keychain_env_sh_gpg"
  23. }
  24. _start_agent
  25. # tidy up after ourselves
  26. unfunction _start_agent