Skip to content

Instantly share code, notes, and snippets.

@bmnn
Last active December 31, 2015 22:09
Show Gist options
  • Save bmnn/8051352 to your computer and use it in GitHub Desktop.
Save bmnn/8051352 to your computer and use it in GitHub Desktop.
emacs; git; shell; grep; save; change buffers; capture shell output; cd; replace regexp;
setq last-search "")
(defun gg (searchstring)
"git-grep the entire current repo"
(cd (replace-regexp-in-string "\n" "" (shell-command-to-string "git rev-parse --show-toplevel")))
(interactive (list (completing-read "Search for: " nil nil nil (concat
last-search " -e "))))
(when buffer-file-name (save-buffer))
(call-process "git" nil "*Messages*" nil "add" "- u")
(call-process "git" nil "*Messages*" nil "add" "\*.org")
(grep-find (concat "git grep -P -n -I -i --full-name --all-match " searchstring))
(switch-to-buffer "*grep*")
(delete-other-windows)
(setq last-search searchstring)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment