Saturday, 15 March 2014

bash - How do I handle password prompts when calling elisp from the terminal -



bash - How do I handle password prompts when calling elisp from the terminal -

i'm trying utilize elisp shell script language. i'm writing script need access file encrypted gpg. i'm not sure how handle password prompt. in examples below, programme called command line (bash).

first try:

#!/usr/bin/emacs --script (setq passwd-file "~/password.gpg") (save-excursion (let ((passwd-buffer (find-file passwd-file))) (switch-to-buffer passwd-buffer) (princ (buffer-substring 1 30))))

this lets me come in password in terminal, password shown in plaintext.

second try

#!/usr/bin/emacs --script (setq passwd-file "~/password.gpg") (setq pstring (shell-command-to-string (concat "gpg -d " passwd-file))) (princ pstring)

this gives error gpg: cannot open tty /dev/tty: no such device or address

you out of luck. first illustration suggests read-passwd not hide password input in non-interactive session, insert-file calls out epa encrypted files, in turn uses read-passwd gpg password input.

try study emacs maintainers m-x report-emacs-bug, asking them suppress input echo in read-passwd in non-interactive sessions. that'd behaviour i'd expect.

for now, cannot work around limitation, because emacs not expose underlying tty emacs lisp code, have no chance manually disable input echo on underlying tty device.

from experience in writing , contributing quite non-interactive emacs lisp programs, i'd advise against using emacs non-interactive scripts. it's poor platform such programs. api limited, , there lot of implicit behaviour standing in way of non-interactive programs, can't rid of.

for instance, cannot safely pass command line arguments emacs, since emacs automatically visit existing file in command line arguments, triggering sorts of side effects such prompts unsafe local variables, etc.

bash shell emacs elisp

No comments:

Post a Comment