One of the commands I find myself running very often is git grep. I would really like it to be accessible through the same magit menu as other commands. However, from my understanding of magit.el, it looks like the items there are hard-coded, and there's no way to add one more, unless I modify the source of this function.
Am I wrong?
Is there a better way?
I read this answer: https://emacs.stackexchange.com/a/12739/563 but I cannot understand what arguments transient-append-suffix needs. Also, it looks like the answer is too old / maybe doesn't work anymore.
What I have so far
(defun wvxvw-magit-grep (regex &optional args) (interactive (list (read-from-minibuffer "Expression: ") (transient-args 'magit-grep))) (let ((invert "") (extended "")) (while args (let ((val (car args))) (cond ((string-equal val "v") (setq invert "-v")) ((string-equal val "E") (setq extended "-E"))) (setq args (cdr args)))) (grep (format "git --no-pager grep -nH%s%s '%s'" invert extended regex)))) (defclass wvxvw-git-grep-expression-cls (transient-variable) ((scope :initarg :scope) (expression :initarg nil))) (transient-define-infix wvxvw-git-grep-expression-cmd () :class wvxvw-git-grep-expression-cls) (transient-define-prefix magit-grep () "Display git-grep command options." :man-page "git-grep" ["Arguments" ("-v" "Invert match" "-v") ("-E" "Extended regexp" "-E")] ["Actions" ("g" "Grep" wvxvw-magit-grep)]) (define-key magit-mode-map "G" 'magit-grep) There's a thing I don't like about it: This doesn't actually add it to the magit-dispatcher menu, so, this isn't available if you press h in Magit status buffer.
project-find-regexpfrom any file or directory within a given git repository. You can bind it to a key of course.