branch: master
commit f5a32bf39a2e0626cdc3cc2234ff632a1da9380a
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
Add a command to grep the current git repo
* counsel.el (counsel-git-grep-function): New defun.
(counsel-git-grep): New command.
---
counsel.el | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/counsel.el b/counsel.el
index c1b90d6..a2a0ad4 100644
--- a/counsel.el
+++ b/counsel.el
@@ -149,6 +149,25 @@
(when file
(find-file file))))
+(defun counsel-git-grep-function (string &optional _pred &rest _unused)
+ "Grep in the current git repository for STRING."
+ (split-string
+ (shell-command-to-string
+ (format "git --no-pager grep --full-name -n --no-color -i -e \"%s\""
string))
+ "\n"
+ t))
+
+(defun counsel-git-grep ()
+ "Grep for a string in the current git repository."
+ (interactive)
+ (let ((val (ivy-read "pattern: " 'counsel-git-grep-function))
+ lst)
+ (when val
+ (setq lst (split-string val ":"))
+ (find-file (car lst))
+ (goto-char (point-min))
+ (forward-line (1- (string-to-number (cadr lst)))))))
+
(defun counsel--generic (completion-fn)
"Complete thing at point with COMPLETION-FN."
(let* ((bnd (bounds-of-thing-at-point 'symbol))