From 09cb7e1f7c85b0ed0d3c682fee833294050f2c3b Mon Sep 17 00:00:00 2001 From: Svend Sorensen Date: Wed, 26 Jul 2017 13:13:41 -0700 Subject: emacs: Use with-editor to wrap "pass edit" Instead of editing the password file directly using Emacs, "pass edit" is run. This allows password-store's git change tracking to work. This adds a dependency on the with-editor Emacs package. --- contrib/emacs/Cask | 2 +- contrib/emacs/password-store.el | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/contrib/emacs/Cask b/contrib/emacs/Cask index d595ea7..474611f 100644 --- a/contrib/emacs/Cask +++ b/contrib/emacs/Cask @@ -4,9 +4,9 @@ (package-file "password-store.el") (development - (depends-on "dash") (depends-on "f") (depends-on "s") + (depends-on "with-editor") (depends-on "ecukes") (depends-on "ert-runner") (depends-on "el-mock")) diff --git a/contrib/emacs/password-store.el b/contrib/emacs/password-store.el index a1be788..1bdcc72 100644 --- a/contrib/emacs/password-store.el +++ b/contrib/emacs/password-store.el @@ -1,10 +1,10 @@ ;;; password-store.el --- Password store (pass) support -;; Copyright (C) 2014 Svend Sorensen +;; Copyright (C) 2014-2017 Svend Sorensen ;; Author: Svend Sorensen ;; Version: 0.1 -;; Package-Requires: ((f "0.11.0") (s "1.9.0")) +;; Package-Requires: ((f "0.11.0") (s "1.9.0") (with-editor "2.5.11")) ;; Keywords: pass ;; This file is not part of GNU Emacs. @@ -33,6 +33,7 @@ (require 'f) (require 's) +(require 'with-editor) (defgroup password-store '() "Emacs mode for password-store." @@ -77,6 +78,15 @@ outputs error message on failure." (s-chomp (buffer-string)) (error (s-chomp (buffer-string))))))) +(defun password-store--run-async (&rest args) + "Run pass asynchronously with ARGS. + +Nil arguments are ignored." + (with-editor-async-shell-command + (mapconcat 'identity + (cons password-store-executable + (delq nil args)) " "))) + (defun password-store--run-init (gpg-ids &optional folder) (apply 'password-store--run "init" (if folder (format "--path=%s" folder)) @@ -99,7 +109,8 @@ outputs error message on failure." (error "Not implemented")) (defun password-store--run-edit (entry) - (error "Not implemented")) + (password-store--run-async "edit" + entry)) (defun password-store--run-generate (entry password-length &optional force no-symbols) (password-store--run "generate" @@ -163,12 +174,9 @@ outputs error message on failure." ;;;###autoload (defun password-store-edit (entry) - "Edit password for ENTRY. - -This edits the password file directly in Emacs, so changes will -need to be commited manually if git is being used." + "Edit password for ENTRY." (interactive (list (password-store--completing-read))) - (find-file (password-store--entry-to-file entry))) + (password-store--run-edit entry)) ;;;###autoload (defun password-store-get (entry) -- cgit v1.2.3