我正在尝试为一些常用的 sudo shell 命令(例如,具有C-c srun (shell-command "sudo /etc/init.d/apache2 restart"))创建快捷键。
我尝试使用上面的直接 shell 命令调用,但它只是将以下内容输出到*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
它实际上并不要求输入密码。我不想使用 启动 Emacs sudo emacs,但我想这是一个选项,如果没有其他方法可以工作的话。
理想的解决方案是 Emacs 中的一个函数(而不是 OS jiggery-pokery 来改变 shell 或sudo命令的行为)。之类的东西(sudo-shell-command "dostuff"),或(with-password-prompt (shell-command "sudo dostuff"))。