counsel: Allow command line args in search

If " -- " appears in the search string split the search string on the
first occurrence with everything before treated as args to the search
and everything after treated as part of the regex.
This commit is contained in:
justbur 2016-01-22 19:49:26 -05:00 committed by syl20bnr
parent 2ed37e4a33
commit 1bf4052f37

View file

@ -22,10 +22,10 @@
(defun spacemacs-ivy/init-counsel () (defun spacemacs-ivy/init-counsel ()
(defvar spacemacs--counsel-commands (defvar spacemacs--counsel-commands
'(("ag" . "ag --vimgrep %S .") '(("ag" . "ag --vimgrep %s %S .")
("pt" . "pt.exe -e --nocolor --nogroup --column %S .") ("pt" . "pt -e --nocolor --nogroup --column %s %S .")
("ack" . "ack --nocolor --nogroup --column %S .") ("ack" . "ack --nocolor --nogroup --column %s %S .")
("grep" . "grep -nrP %S .")) ("grep" . "grep -nrP %s %S ."))
"Alist of search commands and their corresponding commands "Alist of search commands and their corresponding commands
with options to run in the shell.") with options to run in the shell.")
@ -88,11 +88,16 @@ than this amount.")
"Grep in the current directory for STRING." "Grep in the current directory for STRING."
(if (< (length string) 3) (if (< (length string) 3)
(counsel-more-chars 3) (counsel-more-chars 3)
(let ((default-directory counsel--git-grep-dir) (let* ((default-directory counsel--git-grep-dir)
(regex (counsel-unquote-regex-parens (args (if (string-match-p " -- " string)
(setq ivy--old-re (let ((split (split-string string " -- ")))
(ivy--regex string))))) (prog1 (pop split)
(spacemacs//counsel-async-command (format base-cmd regex)) (setq string (mapconcat #'identity split " -- "))))
""))
(regex (counsel-unquote-regex-parens
(setq ivy--old-re
(ivy--regex string)))))
(spacemacs//counsel-async-command (format base-cmd args regex))
nil))))) nil)))))
;; see `counsel-ag' ;; see `counsel-ag'