-
Notifications
You must be signed in to change notification settings - Fork 1
/
my-gpg.el
77 lines (67 loc) · 2.24 KB
/
my-gpg.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
;;; my-gpg --- GPG related stuff
;;
;; Copyright (C) 2014 Alex Bennée
;;
;; Author: Alex Bennée <[email protected]>
;;
;; This file is not part of GNU Emacs.
;;
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;;; Commentary:
;;
;; Mainly we are just dealing with faff for access paths and X/non-X environments
;;
;;; Code:
(require 'use-package)
;; enable EasyPG handling
; gpg-agent confuses epa when getting passphrase
(defun my-squash-gpg (&rest ignored-frame)
"Kill any GPG_AGENT_INFO in our environment."
(setenv "GPG_AGENT_INFO" nil))
;; Keychain access
(when (file-exists-p "~/src/emacs/keychain-environment.git")
(use-package keychain-environment
:load-path "~/src/emacs/keychain-environment.git"
:if (or I-am-at-work I-am-at-home)
:commands keychain-refresh-environment
:defer 60
:config (setq keychain-should-inherit t
keychain-be-quick t)))
;; Fix up the frame so we don't send pinentry to the wrong place
(defun my-fixup-gpg-agent (&optional frame)
"Tweak DISPLAY and GPG_TTY environment variables as appropriate to
`FRAME'."
(when (not frame)
(setq frame (selected-frame)))
(if (display-graphic-p frame)
(setenv "DISPLAY" (terminal-name frame))
(setenv "GPG_TTY" (terminal-name frame))
(setenv "DISPLAY" nil)))
(defun my-grab-ssh-agent-from-tmux ()
"Grab the SSH config from tmux."
(interactive)
(let ((ssh (shell-command-to-string "tmux showenv | grep -v '^-'")))
(list (and ssh
(string-match "SSH_AUTH_SOCK=\\(.*?\\)$" ssh)
(setenv "SSH_AUTH_SOCK" (match-string 1 ssh))))))
(when (getenv "DISPLAY")
(add-hook 'after-make-frame-functions 'my-fixup-gpg-agent))
(use-package epa-file
:if (string-match "socrates" (system-name))
:commands epa-file-enable
:init (epa-file-enable)
:config
(progn
(add-hook 'after-make-frame-functions 'my-squash-gpg t)
(my-squash-gpg)
(epa-file-enable)))
(use-package auth-source-pass
:ensure t
:if (file-exists-p "~/.password-store")
:config (auth-source-pass-enable))
(provide 'my-gpg)
;;; my-gpg.el ends here