summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.el6
-rw-r--r--settings/setup-keychain-environment.el75
2 files changed, 77 insertions, 4 deletions
diff --git a/init.el b/init.el
index 79d9ecf..879325b 100644
--- a/init.el
+++ b/init.el
@@ -1,7 +1,3 @@
-;; Added by Package.el. This must come before configurations of
-;; installed packages. Don't delete this line. If you don't want it,
-;; just comment it out by adding a semicolon to the start of the line.
-;; You may delete these explanatory comments.
(package-initialize)
;; Suppress splash screen
@@ -80,6 +76,7 @@
(require 'setup-flycheck)
(require 'setup-haskell-mode)
(require 'setup-ido)
+(require 'setup-keychain-environment)
(require 'setup-magit)
(require 'setup-markdown-mode)
(require 'setup-multiple-cursors)
@@ -98,4 +95,5 @@
(put 'upcase-region 'disabled nil)
(put 'narrow-to-region 'disabled nil)
+(keychain-refresh-environment)
;;; init.el ends here
diff --git a/settings/setup-keychain-environment.el b/settings/setup-keychain-environment.el
new file mode 100644
index 0000000..6d6c294
--- /dev/null
+++ b/settings/setup-keychain-environment.el
@@ -0,0 +1,75 @@
+;;; keychain-environment.el --- load keychain environment variables
+
+;; Copyright (C) 2011-2016 Jonas Bernoulli
+;; Copyright (C) 2008-2011 Paul Tipper
+
+;; Author: Paul Tipper <bluefoo at googlemail dot com>
+;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
+;; Created: 20081218
+;; Homepage: https://github.com/tarsius/keychain-environment
+;; Keywords: gnupg, pgp, ssh
+
+;; 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.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; For a full copy of the GNU General Public License
+;; see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Keychain is a script that manages ssh-agent and gpg-agent. It is
+;; typically run from the shell's initialization file. It allows your
+;; shells and cron jobs to share a single ssh-agent and/or gpg-agent.
+
+;; When keychain is run, it checks for running agent, otherwise it
+;; starts them. It saves the agents' environment variables to files
+;; inside ~/.keychain/, so that subsequent shells can source these
+;; files.
+
+;; When Emacs is started under X11 and not directly from a terminal
+;; these variables are not set. This library looks for these files
+;; created by keychain and then sets Emacs' environment variables
+;; accordingly. It does not actually run keychain, so you still
+;; have to run that from a login shell first.
+
+;; To use run the function `keychain-refresh-environment' in your
+;; init file. If keychain has not been run yet when you start Emacs
+;; you can also later call that function interactively.
+
+;; Also see: http://www.funtoo.org/wiki/Keychain
+
+;;; Code:
+
+;;;###autoload
+(defun keychain-refresh-environment ()
+ "Set ssh-agent and gpg-agent environment variables.
+Set the environment variables `SSH_AUTH_SOCK', `SSH_AGENT_PID'
+and `GPG_AGENT' in Emacs' `process-environment' according to
+information retrieved from files created by the keychain script."
+ (interactive)
+ (let* ((ssh (shell-command-to-string "keychain -q --noask --agents ssh --eval"))
+ (gpg (shell-command-to-string "keychain -q --noask --agents gpg --eval")))
+ (list (and ssh
+ (string-match "SSH_AUTH_SOCK[=\s]\\([^\s;\n]*\\)" ssh)
+ (setenv "SSH_AUTH_SOCK" (match-string 1 ssh)))
+ (and ssh
+ (string-match "SSH_AGENT_PID[=\s]\\([0-9]*\\)?" ssh)
+ (setenv "SSH_AGENT_PID" (match-string 1 ssh)))
+ (and gpg
+ (string-match "GPG_AGENT_INFO[=\s]\\([^\s;\n]*\\)" gpg)
+ (setenv "GPG_AGENT_INFO" (match-string 1 gpg))))))
+
+(provide 'setup-keychain-environment)
+;; Local Variables:
+;; indent-tabs-mode: nil
+;; End:
+;;; setup-keychain-environment.el ends here