(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 <> 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 <>.age <>" my/age-pubkey) :utils "age" :post-process-template #'my/dwim-shell-command/convert-path-cygwin))