magit调用git命令时间很长的时候, 怎么显示一个标识或者进度?

$ (magit-process-buffer) 会显示 Git 的输出(状态)。

(info "(magit) How to show git's output?")

我用的老版本, 没这功能, 试了下新版本, 有这个功能, 不过标识不够明显.

magit 有很多 hook,你可以自己加上你喜欢的

如果标志太明显,有时候反而是一种干扰。

如果你觉得某个git的结果比较重要,不妨耐心等一下,或者做一些不用专注其中的工作。

这个功能知道. 我是说, 等待时间太长, 我可能会切换到其他buffer, 比如开始编辑文件了, 此时就不在magit的buffer里了, 那么这个快捷键就没法用. 也很容易把magit后台提交这件事忘记.

对我来说git提交成功失败比编辑文件更重要, 所以不感觉干扰, 我倒是希望可以设置个语音提醒, 或者系统通知.

主要是形成了习惯, 每天提交次数太多了, 每次都等, 合起来浪费不少时间.

没想过这样的需要,很重要的话一般稍微等下就 OK 了。Magit Buffer 的 Mode Line 上有显示 Git 的状态,失败时也会提示,我相信不难实现在全局的 Mode Line 显示,或者用声音来提示。

不知道你说的提交是 commit 还是 push。如果是 commit,看看git-commit-post-finish-hook

在 magit buffer 中状态都会显示在 mode line 上,不过你要是关闭了当然就看不到了,建议提交时不要关闭当前 buffer。

可能我push次数太多,每天几十次,以前用oschina的感觉快一点,还能等,github的明显慢不少。

看代码找到地方了,准备加个系统通知。

多谢截图和说明,截图效果不错,主题不错,不过蓝色长时间看好像对眼睛不好

我这边察觉不出慢,我一直用代理:

[http]
        proxy = socks5://localhost:1080
[url "https://github.com/"]
        insteadOf = [email protected]:

(SSH (git@…) 貌似不能用 HTTP / Socks 代理,所有统一用 http://

还好,蓝色并不多,截小图你看着多,尤其晚上加night shift正好。

OK了. linux上效果:

image

image

成功的通知5秒后消失, 失败的通知需要手动点击才消失. 达到我想要的效果.

mac上好像没法控制显示时间和图标, 只好通过声音来区分.

另外, 只有当前buffer不是magit的buffer时候才会通知, 否则不通知.

1 个赞

你这是commit还是push?

BTW:如果是频繁check in,咣咣弹出提醒岂不是很分心?

push和pull, 每次操作大概等待4到8秒左右, 每天大概操作20次左右.

没有代理, 没有vpn, 一直裸奔.

酷炫,期待分享

基于网上找的一个notify.el修改了一下, 增加了错误通知接口, 另外增加了一个通知后端, 在macos上使用osacript来发送系统通知:

然后再修改magit的进程结束处理函数, 我用的是magit 1.x, 修改比较简单:

--- a/.lisp/magit/magit.el
+++ b/.lisp/magit/magit.el
@@ -2170,7 +2170,16 @@ function can be enriched by magit extension like magit-topgit and magit-svn"
         (dired-uncache default-directory)))
     (setq magit-process nil)
     (magit-set-mode-line-process nil)
-    (magit-refresh-buffer magit-process-client-buffer)))
+    (magit-refresh-buffer magit-process-client-buffer)
+	;;+Added by zhanghj([email protected]) at 13:17 04/26/2019
+  	(unless (get-buffer-window magit-process-client-buffer)
+	  (let ((repo-dir (with-current-buffer magit-process-client-buffer
+						(magit-get-top-dir default-directory))))
+		(if successp
+			(my-notify "magit result: OK"
+					   (format "%s\n------\nrepo: %s" msg repo-dir))
+		  (my-notify-critical "magit result: failed"
+							  (format "%s\n------\nrepo: %s" msg repo-dir)))))))
 
 (defun magit-password (proc string)
   "Checks if git/ssh asks for a password and ask the user for it."

magit 2.x的没怎么用过, 看了一下, 可以尝试修改magit-process-finish函数.

1 个赞

你是基于 EmacsWiki: notify.el 这份源代码修改的吧?

大佬 @jwiegley 有个 alert.el 功能似乎不少(里边还有个基于 frame 的通知功能没实现完):

| Name          | Summary                                                            |
| ------------- | ------------------------------------------------------------------ |
| fringe        | Changes the current frame's fringe background color                |
| mode-line     | Changes the current frame's mode-line background color             |
| gntp          | Uses gntp, it requires [gntp.el](https://github.com/tekai/gntp.el) |
| growl         | Uses Growl on OS X, if growlnotify is on the PATH                  |
| ignore        | Ignores the alert entirely                                         |
| libnotify     | Uses libnotify if notify-send is on the PATH                       |
| log           | Logs the alert text to *Alerts*, with a timestamp                  |
| message       | Uses the Emacs `message` facility                                  |
| notifications | Uses notifications library via D-Bus                               |
| notifier      | Uses terminal-notifier on OS X, if it is on the PATH               |
| osx-notifier  | Native OSX notification using AppleScript                          |
| toaster       | Use the toast notification system                                  |
| x11           | Changes the urgency property of the window in the X Window System

Emacs 内置了一个 notifications.el 不过依赖 DBUS,在 macOS 下用不了。

还有 terminal-notifiernode-notifier 等命令行工具:eshell 一个命令完成时在modeline提醒 - #2,来自 twlz0ne

我觉得还是系统通知靠谱,emacs被最小化之后自己实现的通知很难被注意到。

terminal-notifier在tmux下不能用,装了另外一个跟他配合的插件,当时好像遇到了死机,所以这些外部非必须得工具都删了,感觉用系统自带的兼容比较好,也通用。

alert.el代码太多了,一百多行可以实现的功能用了一千行。我喜欢简单直接够用的。