emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master f5a32bf 04/18: Add a command to grep the current git repo


From: Oleh Krehel
Subject: [elpa] master f5a32bf 04/18: Add a command to grep the current git repo
Date: Mon, 20 Apr 2015 12:39:02 +0000

branch: master
commit f5a32bf39a2e0626cdc3cc2234ff632a1da9380a
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]