我试图为一些常用的sudo shell命令创建快捷键(例如,有C-c s
运行(shell-command "sudo /etc/init.d/apache2 restart")
)。如何在Emacs中运行sudo命令?
我试着使用上述直了壳命令调用,但它只是输出以下为*Shell Command Output*
缓冲区:
[sudo] password for Inaimathi:
Sorry, try again.
[sudo] password for Inaimathi:
Sorry, try again.
[sudo] password for Inaimathi:
Sorry, try again.
sudo: 3 incorrect password attempts
实际上它并不要求提供密码。我不想使用sudo emacs
启动Emacs,但我想这是一个选项,如果没有其他的工作。
理想的解决方案是Emacs中的一个函数(与OS Jiggery-pokery相反,用于更改shell或sudo
命令的行为)。类似于(sudo-shell-command "dostuff")
或(with-password-prompt (shell-command "sudo dostuff"))
。
相关(近似重复?):http://stackoverflow.com/questions/95631/open-a-file-with-su-sudo-inside-emacs和投票迁移到超级用户可能是正确的。 @Inaimathi:如果这与编程密切相关,现在是解释原因的好时机,否则这些问题可能会转移到更适合的地方。 – dmckee 2010-03-18 18:25:58
鉴于OP正试图将某个elisp绑定到某个密钥,这对我来说足够程序化。 – dmckee 2010-03-18 18:34:18
调整问题以缓解一些混乱。 – Inaimathi 2010-03-18 19:21:42