如何绑定密钥以在dired emacs中运行shell命令

当我在emacs中使用dired模式时,我可以按类型!xxx运行 shell命令,但是如何绑定一个键来运行此命令?
例如,我想在文件上按O,然后dired将运行’cygstart’来打开这个文件.
您可以使用shell命令功能.例如:
(defun ls ()
  "Lists the contents of the current directory."
  (interactive)
  (shell-command "ls"))

(global-set-key (kbd "C-x :") 'ls); Or whatever key you want...

要在单个缓冲区中定义命令,可以使用local-set-key.在dired中,您可以使用dired-file-name-at-point获取文件名称.所以,要完全按照你的要求做:

(defun cygstart-in-dired ()
  "Uses the cygstart command to open the file at point."
  (interactive)
  (shell-command (concat "cygstart " (dired-file-name-at-point))))
(add-hook 'dired-mode-hook '(lambda () 
                              (local-set-key (kbd "O") 'cygstart-in-dired)))

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...