Customizing commands ran by magit

15 views
Skip to first unread message

John Shahid

unread,
Feb 21, 2019, 4:36:32 PM2/21/19
to ma...@googlegroups.com
Hi all,

Is there a way to customize the command that magit run when I commit,
e.g. using `git ci' (a user defined alias) instead of `git commit' ? I
used to have a popup action to run `git ci' bound to "i". With the
recent switch to transient my customization broke as it used to rely on
`magit-popup'. I replaced my previous hack with the following advice:

(defun shahid/magit-replace-command (args)
(message "called with: %S " args)
(pcase-let ((`(,cmd . ,args) args))
(cond
((string-equal cmd "commit") (cons "ci" args))
(t (cons cmd args)))))

(advice-add #'magit-run-git-with-editor
:filter-args
#'shahid/magit-replace-command)

But I'm wondering if there is any interest in making the commands used
by magit customizable ?

Cheers,

JS

Kyle Meyer

unread,
Feb 21, 2019, 8:34:44 PM2/21/19
to John Shahid, ma...@googlegroups.com
Hi John,

John Shahid <jvsh...@gmail.com> writes:

> Hi all,
>
> Is there a way to customize the command that magit run when I commit,
> e.g. using `git ci' (a user defined alias) instead of `git commit' ? I
> used to have a popup action to run `git ci' bound to "i". With the
> recent switch to transient my customization broke as it used to rely on
> `magit-popup'. I replaced my previous hack with the following advice:
>
> (defun shahid/magit-replace-command (args)
> (message "called with: %S " args)
> (pcase-let ((`(,cmd . ,args) args))
> (cond
> ((string-equal cmd "commit") (cons "ci" args))
> (t (cons cmd args)))))

Since you're going with pcase-let, you could simplify this to something
like (untested):

(defun shahid/magit-replace-command (args)
(message "called with: %S " args)
(pcase args
(`("commit" . ,rest) (cons "ci" rest))
(_ args)))

> (advice-add #'magit-run-git-with-editor
> :filter-args
> #'shahid/magit-replace-command)
>
> But I'm wondering if there is any interest in making the commands used
> by magit customizable ?

IMO an option for configuring subcommands isn't something Magit should
support. I think the above use case is a good fit for advice.


--
Kyle
Reply all
Reply to author
Forward
0 new messages