【发布时间】:2014-06-22 15:27:56
【问题描述】:
我正在尝试使用 elisp 作为 shell 脚本语言。我正在编写一个脚本,我需要访问一个用 gpg 加密的文件。我不确定如何处理密码提示。在下面的示例中,他的程序是从命令行 (bash) 调用的。
第一次尝试:
#!/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))))
这让我可以在终端中输入密码,但密码以明文形式显示。
第二次尝试
#!/usr/bin/emacs --script
(setq passwd-file "~/password.gpg")
(setq pstring (shell-command-to-string (concat "gpg -d " passwd-file)))
(princ pstring)
这给出了错误gpg: cannot open tty /dev/tty: No such device or address
【问题讨论】:
-
不要不将
find-file用于文件IO。它可能会导致任意副作用,并可能在非交互式会话中阻塞 Emacs。 -
这样的东西有帮助吗?
(read-passwd "Password: ")这是此函数可用参数的打印输出:(read-passwd PROMPT &optional CONFIRM DEFAULT) -
lunaryorn:我应该改用什么?我查看了 elisp 手册,但没有找到任何明确的 IO 内容。
-
lawlist:从终端调用时,该函数似乎不起作用。
-
@snowape 报告于debbugs.gnu.org/cgi/bugreport.cgi?bug=17839。您可能想加入讨论以表达您的支持。