让Emacs shell命令发送桌面通知

系统 Linux Windows
我总是使用 Eshell 来与操作系统进行交互,因为它与 Emacs 无缝整合、支持处理 (远程) TRAMP 文件,而且在 Windows 上也能工作得很好。

[[268140]]

 我总是使用 Eshell 来与操作系统进行交互,因为它与 Emacs 无缝整合、支持处理 (远程) TRAMP 文件,而且在 Windows 上也能工作得很好。

启动 shell 命令后 (比如耗时严重的构建任务) 我经常会由于切换缓冲区而忘了追踪任务的运行状态。

多亏了 Emacs 的 钩子 机制,你可以配置 Emacs 在某个外部命令完成后调用一个 elisp 函数。

我使用 John Wiegleys 所编写的超棒的 alert 包来发送桌面通知:

  1. (require 'alert)
  2.  
  3. (defun eshell-command-alert (process status)
  4. "Send `alert' with severity based on STATUS when PROCESS finished."
  5. (let* ((cmd (process-command process))
  6. (buffer (process-buffer process))
  7. (msg (format "%s: %s" (mapconcat 'identity cmd " ") status)))
  8. (if (string-prefix-p "finished" status)
  9. (alert msg :buffer buffer :severity 'normal)
  10. (alert msg :buffer buffer :severity 'urgent))))
  11.  
  12. (add-hook 'eshell-kill-hook #'eshell-command-alert)

alert 的规则可以用程序来设置。就我这个情况来看,我只需要当对应的缓冲区不可见时得到通知:

  1. (alert-add-rule :status '(buried) ;only send alert when buffer not visible
  2. :mode 'eshell-mode
  3. :style 'notifications)

这甚至对于 TRAMP 也一样生效。下面这个截屏展示了失败的 make 命令产生的 Gnome 桌面通知。

责任编辑:庞桂玉 来源: Linux中国
相关推荐

2011-07-20 10:18:41

EmacsShell

2022-07-14 15:00:53

Linux 终端通知脚本命令

2011-07-19 10:16:55

2017-06-26 19:00:46

LinuxShell命令

2019-03-12 21:00:15

WindowsEmacsShell

2015-12-28 12:03:44

LinuxUnix桌面

2020-02-26 13:47:57

Emacs电子邮件开源

2020-11-29 17:32:01

EmacsLinux

2020-02-27 13:43:14

Emacs俄罗斯方块应用

2023-06-08 12:37:17

2014-12-25 09:56:23

2011-03-23 12:55:51

NagiosMSN飞信

2021-11-06 19:43:34

Python微信服务器

2017-10-23 16:27:11

HTML5桌面Notificatio

2011-05-31 16:05:41

WidgetiOS 5

2009-03-10 19:03:11

Linux图形环境桌面

2019-12-01 22:59:43

Linux shell命令进程

2014-08-06 09:57:15

hadoop ShelShell命令

2022-05-20 13:46:36

Linux激活Linux水印

2022-01-10 09:20:30

Maui ShellLinux桌面
点赞
收藏

51CTO技术栈公众号