[英]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.