eshell 一个命令完成时在modeline提醒

在eshell里执行个耗时较长的命令,然后切换到了其他buffer。 希望在这个命令完成时候,在modeline通知。

eshell有反应当前状态(运行中还是空闲)的变量或者函数吗?

mode-line 反映的是当前 buffer 的状态,所以当你离开 eshell 之后,就不应该在 mode-line 看到 eshell 了。

eshell 除了执行 shell 命令,也可以直接运行 elisp:

@eshell ~ $ sleep 5 && (message "finished")

然后在 minibuffer 能看到输出结果 finished

还可以通过 terminal-notifier(macOS) / node-notifier 发送桌面通知,这个效果比 minibuffer 更醒目:

@eshell ~ $ sleep 5 && terminal-notifier -message "finished"

或者封装一个 elisp 函数:

@eshell ~ $ sleep 5 && (notify "finished")
1 个赞

对哦eshell里能用elisp给忘了哈哈哈 thx~

Eshell 默认就会在 Mode line 显示命令运行的状态: ** 表示运行中,--表示空闲。当然不仔细看可能看不出来。值得注意的是这个状态是 Buffer Local 的,因为 Eshell 本身可以同时运行在不同的 Buffer 里。

eshell-status-in-mode-line is a variable defined in `esh-mode.el'.
Its value is t

Documentation:
If non-nil, let the user know a command is running in the mode line.

You can customize this variable.

eshell-command-running-string 或许可以,比如假设你想获得运行在 *eshell* Buffer 中的 Eshell 的状态的话:

(with-current-buffer "*eshell*"
  eshell-command-running-string)
     => "--"

(with-current-buffer "*eshell*"
  (goto-char (point-max))
  (insert "sleep 3")
  (eshell-send-input)
  eshell-command-running-string)
     => "**"

不过它或许不足以帮助你解决你的需求,因为有延迟的缘故。你需要有一个地方允许你在 Eshell 的运行状态发生改变时及时地更新 Mode Line。

3 个赞

多谢解释~ ~