Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. (defun my-fixup-gpg-agent (frame)
  2. "Tweak DISPLAY and GPG_TTY environment variables as appropriate to `FRAME'."
  3. (when (fboundp 'keychain-refresh-environment)
  4. (keychain-refresh-environment))
  5. (if (display-graphic-p frame)
  6. (setenv "DISPLAY" (terminal-name frame))
  7. (setenv "GPG_TTY" (terminal-name frame))
  8. (setenv "DISPLAY" nil)))
  9.  
  10. (add-hook 'after-make-frame-functions 'my-fixup-gpg-agent)
  11.  
  12. ;; Simple caching
  13. (defvar my-cached-passwords
  14. nil
  15. "Cache of passwords. Stored in plain text so you only want to cache
  16. them if of low value.")
  17.  
  18. (defun my-pass-password (pass-name &optional cache)
  19. "Return the password for the `PASS-NAME'."
  20. (let ((cached-pass (assoc-default pass-name my-cached-passwords)))
  21. (if cached-pass
  22. cached-pass
  23. (when (selected-frame)
  24. (my-fixup-gpg-agent (selected-frame))
  25. (let ((new-pass (chomp
  26. (shell-command-to-string
  27. (format "pass %s" pass-name)))))
  28. (when (and new-pass cache)
  29. (add-to-list 'my-cached-passwords (cons pass-name new-pass)))
  30. new-pass)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement