[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to streamline my Magit workflow?
From: |
Kyle Meyer |
Subject: |
Re: How to streamline my Magit workflow? |
Date: |
Sat, 29 Oct 2022 13:03:16 -0400 |
Marcin Borkowski writes:
> Now, I'd like to streamline my workflow. Instead of pressing `$',
> finding that URL and copying it to my browser, I'd like to either have
> it done automatically after a push or triggered with a custom command.
>
> So, my questions are:
>
> 1. How can I access the "magit process buffer" of the repo I'm in from
> Elisp?
>
> 2. Is there some hook which runs after a (Magit) push is completed?
To get something to fire once the process completes, you could latch
onto magit-process-sentinel (or magit-process-finish, which is called by
magit-process-sentinel). For example, something like
(defun my/magit-open-pr-after-push (process event)
(when (and (memq (process-status process) '(exit signal))
(= (process-exit-status process) 0))
(let ((buf (process-buffer process))
(section (process-get process 'section)))
(when (buffer-live-p buf)
(with-current-buffer buf
(message "%s"
(buffer-substring-no-properties
(oref section content)
(oref section end))))))))
(advice-add 'magit-process-sentinel :after #'my/magit-open-pr-after-push)
where (message ...) is replaced by code that calls browse-url if a PR
link is found.
You may want to also advise the particular magit-push-* command you use
to process-put a flag so the output search isn't triggered for other
async Magit commands.