Skip to content

Instantly share code, notes, and snippets.

@jglick
Last active June 1, 2023 21:21
Show Gist options
  • Save jglick/bd7ba2ffb2b0ed155f0d38bf4c1ba5e1 to your computer and use it in GitHub Desktop.
Save jglick/bd7ba2ffb2b0ed155f0d38bf4c1ba5e1 to your computer and use it in GitHub Desktop.

Revisions

  1. jglick revised this gist Jun 1, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-grep-dired.el
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    (setq buffer-read-only nil)
    (erase-buffer)
    (setq default-directory repo)
    (let ((cmd (format "git --git-dir %s/.git ls-files -z%s | xargs -0 grep -lZ -- %s | xargs -0 ls -l"
    (let ((cmd (format "git --git-dir %s/.git ls-files --recurse-submodules -z%s | xargs -0 grep -lZ -- %s | xargs -0 ls -l"
    repo
    (apply 'concat (mapcar (lambda (s) (concat " " (shell-quote-argument s))) (split-string wildcards)))
    (shell-quote-argument regexp))))
  2. jglick created this gist Dec 8, 2016.
    18 changes: 18 additions & 0 deletions git-grep-dired.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    (defun git-grep-dired (repo wildcards regexp)
    "Find Git-controlled files in DIR with a name like WILDCARDS containing a regexp REGEXP and start Dired on output."
    (interactive "DGit-grep (directory): \nsGit-grep (filename wildcard(s), e.g. *.xml): \nsGit-grep (grep regexp): ")
    (setq repo (file-name-as-directory (expand-file-name repo)))
    (switch-to-buffer (concat "*Git Grep " repo "*"))
    (fundamental-mode)
    (setq buffer-read-only nil)
    (erase-buffer)
    (setq default-directory repo)
    (let ((cmd (format "git --git-dir %s/.git ls-files -z%s | xargs -0 grep -lZ -- %s | xargs -0 ls -l"
    repo
    (apply 'concat (mapcar (lambda (s) (concat " " (shell-quote-argument s))) (split-string wildcards)))
    (shell-quote-argument regexp))))
    (insert " " cmd "\n " repo ":\n")
    (call-process-shell-command (concat cmd " | sed -e 's/^/ /g'") nil t))
    (dired-mode)
    (dired-build-subdir-alist)
    (goto-line 2))