emacs - 如何为 emacs eshell 定义备用命令

标签 emacs eshell

我正在尝试开始在 emacs 中使用 eshell 代替 bash,但我严重依赖多年来编写的 bash 函数。我想将 eshell 配置为在出现“未找到命令”情况时调用 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 $ 

最佳答案

这是我最终想出的:

(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))))

关于emacs - 如何为 emacs eshell 定义备用命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9420270/

相关文章:

emacs - 使用 Emacs Starter Kit 时禁用 Emacs 中的 hl-line?

emacs - 将 .emacs 配置文件放置在版本存储库下

Linux emacs/纳米 : how to select all text lines in a larger file and copy

bash - 如何格式化 emacs 组织模式表中的一列数字?

Emacs 外壳。如何在按 RET 时读取命令行的内容

emacs - 如何在右侧窗口中打开 emacs-nav 缓冲区?

emacs - 如何通过 eshell 在 Emacs 中打开文件?

emacs - 如何将 Zsh 别名复制到 Eshell

erlang - erlang如何:now() work?

emacs - 在 emacs 的 eshell 中调用 su