繁体   English   中英

如何为emacs eshell定义替代命令

[英]How to define an alternate command for emacs eshell

我正在尝试开始使用eshell代替emacs中的bash,但是我严重依赖我多年来编写的bash函数。 我想将eshell配置为在出现“未找到命令”条件时调用bash,以防将有关命令实现为bash函数。

有一个诱人的名字叫eshell-alternate-command-hook的变量听起来像是按订单生产的,但是我认为缺乏灵活的技能会干扰我的成功。

这是我的最大努力:

(add-hook 'eshell-alternate-command-hook 'invoke-bash t t)
(defun invoke-bash (command args)
  (throw 'eshell-replace-command
     (list "bash -c" command args)))

但是当我测试它时,它不起作用:

c:/temp $ lsd
Wrong number of arguments: (lambda (command args) (throw (quote eshell-replace-command) (list "bash -c" command args))), 1
c:/temp $ 

这是我最终想出的:

(defun invoke-bash (command)
(progn 
  (setq invoke-bash-cmd (concat "bash -c \"" command " " (mapconcat 'identity eshell-last-arguments " ") "\""))
  (message invoke-bash-cmd)
  (throw 'eshell-replace-command
     (eshell-parse-command invoke-bash-cmd))))

我不是eshell专家,但是在使用此钩子的地方,我看到它仅接收一个参数-命令,您试图执行该命令,因此您的代码看起来像

(add-hook 'eshell-alternate-command-hook 'invoke-bash)
(defun invoke-bash (command)
  (throw 'eshell-replace-command
     (list "bash -c" command)))

但这不起作用,因为您需要返回elisp函数,而不是命令名称(根据文档)。 如果要运行bash,则需要返回具有完整路径的字符串,但是我还没有找到如何将其他参数传递给bash的方法。 也许您可以在Emacs Wiki的相应部分中找到更多内容?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM