从终端调用elisp时,如何处理密码提示 [英] How do I handle password prompts when calling elisp from the terminal

查看:191
本文介绍了从终端调用elisp时,如何处理密码提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用elisp作为一个shell脚本语言。我正在写一个脚本,我需要访问使用gpg加密的文件。我不知道如何处理密码提示。在下面的例子中,他的程序是从命令行(bash)调用的。

I'm trying to use elisp as a shell script language. I'm writing a script where I need access to a file encrypted with gpg. I'm not sure how to handle the password prompt. In the examples below, he program is called from the command line (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))))

这可以让我在终端中输入密码,但密码显示为明文。

This lets me enter the password in the terminal, but the password is shown in plaintext.

第二次尝试

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

这会给出错误 gpg:无法打开tty / dev / tty:没有这样的设备或地址

推荐答案

你可能没有运气。您的第一个例子表明,即使 read-passwd 也不会在非交互式会话中隐藏输入密码,如 insert-file 向EPA发出加密文件,然后再为GPG密码输入使用 read-passwd

You are likely out of luck. You first example suggests that even read-passwd does not hide the password input in a non-interactive session, as insert-file calls out to EPA for encrypted files, which in turn uses read-passwd for GPG password input.

尝试使用 Mx report-emacs-bug 向Emacs维护者报告,要求他们在 read-passwd 在非交互式会话中。这将是我期望的行为。

Try to report this to the Emacs maintainers with M-x report-emacs-bug, asking them to suppress input echo in read-passwd in non-interactive sessions. That'd be the behaviour I'd expect.

现在,您无法解决此限制,因为Emacs不会将基础TTY暴露于Emacs Lisp代码,所以您没有机会手动禁用基础TTY设备上的输入回显。

For now, you cannot work around this limitation, because Emacs does not expose the underlying TTY to Emacs Lisp code, so you have no chance to manually disable input echo on the underlying TTY device.

根据我在撰写和贡献相当一些非交互式Emacs Lisp程序的经验,我亲自建议不要使用Emacs进行非交互式脚本。这是一个很差的平台。 API是有限的,并且有很多隐含的行为站在非互动程序的方式,你不能摆脱。

From my experience in writing and contributing quite some non-interactive Emacs Lisp programs, I'd personally advise against using Emacs for non-interactive scripts. It's a poor platform for such programs. The API is limited, and there is a lot of implicit behaviour standing in the way of non-interactive programs, which you can't get rid of.

例如,您不能安全地将命令行参数传递给Emacs,因为Emacs将自动访问其命令行参数中的任何现有文件,从而触发各种副作用,例如不安全局部变量的提示等。

For instance, you cannot safely pass command line arguments to Emacs, since Emacs will automatically visit any existing file in its command line arguments, triggering all sorts of side effects such as prompts for unsafe local variables, etc.

这篇关于从终端调用elisp时,如何处理密码提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆