Let Emacs shell command sends desktop notifications | Linux China

640?wx_fmt=jpeg Thanks Emacs hook mechanism, you can configure Emacs elisp call a function after the completion of an external command. - Jürgen Hötzel

I always use  Eshell  to interact with the operating system because it seamlessly integrates with Emacs, support processing (remote)  TRAMP file, but also on Windows can work very well.

After starting the shell command (such as time-consuming task of building serious) I often forget to run due to the switching buffer status tracking task.

Thanks to the Emacs  hook  mechanism, you can configure Emacs elisp call a function after the completion of an external command.

I use  John Wiegleys  awesome written  alert  package to send desktop notifications:

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

alert  rules can be set by the program. For me this situation, when I just need to be notified when the corresponding buffer is not visible:

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

This even for  TRAMP  also become effective. The following screenshot shows the failure of the  make Gnome desktop notifications generated command.

640?wx_fmt=png


via: https://blog.hoetzel.info/post/eshell-notifications/

Author: Jürgen Hötzel  topics: lujun9972  Translator: lujun9972  proofread: wxy

This article from the  LCTT  original compiler, Linux China  is proud

640?wx_fmt=jpeg


Guess you like

Origin blog.csdn.net/F8qG7f9YD02Pe/article/details/92265777