Add gist to encrypt files with dwim-shell-command
This commit is contained in:
parent
509cccce46
commit
69fe8a2d8f
31
gists.org
31
gists.org
|
@ -496,6 +496,37 @@ It turns out it didn't work as well as I hoped, paredit steals the RET binding s
|
|||
(advice-add #'tempel-insert :around #'my/store-region)
|
||||
#+end_src
|
||||
|
||||
* dwim-shell-command to encrypt files with age :emacs:age:
|
||||
|
||||
#+begin_src elisp :tangle gists/dwim-shell-command-encrypt-with-age.el
|
||||
(defconst my/cygwin-p (string-equal system-type "cygwin"))
|
||||
(defconst my/age-pubkey "ageXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
|
||||
|
||||
(defun my/dwim-shell-command/convert-path-cygwin (template unix-path)
|
||||
"Convert a Unix path to a Windows path.
|
||||
|
||||
This can be used as a :post-process-template of a
|
||||
dwim-shell-command-on-marked-files function, where <<f>>
|
||||
templates expand to Unix-like paths. However, a non-Cygwin binary
|
||||
does not understand Unix paths so use cygpath to convert it."
|
||||
(if my/cygwin-p
|
||||
(let* ((command (format "cygpath -w %s" unix-path))
|
||||
(cygwin-path (string-trim (shell-command-to-string command)))
|
||||
(escaped-cygwin-path (string-replace "\\" "\\\\" cygwin-path)))
|
||||
(string-replace unix-path escaped-cygwin-path template))
|
||||
|
||||
;; just return the template as-is
|
||||
template))
|
||||
|
||||
(defun my/dwim-shell-command/age-encrypt ()
|
||||
"Encrypt marked files with the age encryption tool."
|
||||
(interactive)
|
||||
(dwim-shell-command-on-marked-files "Age Encypt"
|
||||
(format "age -e -r %s -o <<f>>.age <<f>>" my/age-pubkey)
|
||||
:utils "age"
|
||||
:post-process-template #'my/dwim-shell-command/convert-path-cygwin))
|
||||
#+end_src
|
||||
|
||||
* Meta
|
||||
** License
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
(defconst my/cygwin-p (string-equal system-type "cygwin"))
|
||||
(defconst my/age-pubkey "ageXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
|
||||
|
||||
(defun my/dwim-shell-command/convert-path-cygwin (template unix-path)
|
||||
"Convert a Unix path to a Windows path.
|
||||
|
||||
This can be used as a :post-process-template of a
|
||||
dwim-shell-command-on-marked-files function, where <<f>>
|
||||
templates expand to Unix-like paths. However, a non-Cygwin binary
|
||||
does not understand Unix paths so use cygpath to convert it."
|
||||
(if my/cygwin-p
|
||||
(let* ((command (format "cygpath -w %s" unix-path))
|
||||
(cygwin-path (string-trim (shell-command-to-string command)))
|
||||
(escaped-cygwin-path (string-replace "\\" "\\\\" cygwin-path)))
|
||||
(string-replace unix-path escaped-cygwin-path template))
|
||||
|
||||
;; just return the template as-is
|
||||
template))
|
||||
|
||||
(defun my/dwim-shell-command/age-encrypt ()
|
||||
"Encrypt marked files with the age encryption tool."
|
||||
(interactive)
|
||||
(dwim-shell-command-on-marked-files "Age Encypt"
|
||||
(format "age -e -r %s -o <<f>>.age <<f>>" my/age-pubkey)
|
||||
:utils "age"
|
||||
:post-process-template #'my/dwim-shell-command/convert-path-cygwin))
|
Loading…
Reference in New Issue