我正在尝试在emacs中使用eshell来代替bash,但我在很大程度上依赖于我多年来编写的bash函数。我想要配置ESCHEL来在出现“命令找不到”的情况时调用bash,以防有问题的命令被实现为bash函数。
有一个名为eshell-alternate-command-hook的变量听起来像是按订单定制的,但我认为我的elisp技能的缺乏阻碍了我的成功。
这是我最大的努力:
(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 $ 发布于 2012-02-25 01:59:51
这就是我最终想到的:
(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))))发布于 2012-02-24 04:32:32
我不是eshell专家,但是在使用这个钩子的地方,我看到它只接收一个参数-您试图执行的命令,所以您的代码可能看起来像这样
(add-hook 'eshell-alternate-command-hook 'invoke-bash)
(defun invoke-bash (command)
(throw 'eshell-replace-command
(list "bash -c" command)))但它不起作用,因为您需要返回elisp函数,而不是命令名(根据文档)。如果您想运行bash,那么您需要返回带有完整路径的字符串,但是我还没有找到如何将额外的参数传递给bash。也许你可以在corresponding section on Emacs Wiki中找到更多
https://stackoverflow.com/questions/9420270
复制相似问题