diff --git a/modules/completion/ivy/autoload/evil.el b/modules/completion/ivy/autoload/evil.el index 2f04b57c1..da25f046d 100644 --- a/modules/completion/ivy/autoload/evil.el +++ b/modules/completion/ivy/autoload/evil.el @@ -49,6 +49,16 @@ (setq +ivy--file-last-search query) (require 'counsel) (pcase engine + ('grep + (let ((args (if recursion-p " -r")) + (counsel-projectile-grep-initial-input query)) + (if all-files-p + (cl-letf (((symbol-function #'projectile-ignored-directories-rel) + (symbol-function #'ignore)) + ((symbol-function #'projectile-ignored-files-rel) + (symbol-function #'ignore))) + (counsel-projectile-grep args)) + (counsel-projectile-grep args)))) ('ag (let ((args (concat (if all-files-p " -a") @@ -65,6 +75,17 @@ ('pt) ;; TODO pt search engine (necessary?) (_ (error "No search engine specified"))))) +;;;###autoload (autoload '+ivy:grep "completion/ivy/autoload/evil" nil t) +(evil-define-operator +ivy:grep (beg end query &optional all-files-p directory) + "Perform a project file search using grep (or git-grep in git repos). QUERY is +a grep regexp. If omitted, the current selection is used. If no selection is +active, the last known search is used. + +If ALL-FILES-P, don't respect .gitignore files and search everything." + (interactive "") + (let ((+ivy--file-search-all-files-p all-files-p)) + (+ivy--file-search 'grep beg end query directory))) + ;;;###autoload (autoload '+ivy:ag "completion/ivy/autoload/evil" nil t) (evil-define-operator +ivy:ag (beg end query &optional all-files-p directory) "Perform a project file search using the silver search. QUERY is a pcre @@ -90,6 +111,14 @@ NOTE: ripgrep doesn't support multiline searches (yet)." (+ivy--file-search 'rg beg end query directory))) +;;;###autoload (autoload '+ivy:ag-cwd "completion/ivy/autoload/evil" nil t) +(evil-define-operator +ivy:grep-cwd (beg end query &optional bang) + "The same as :git, but searches the current directory. If BANG, don't recurse +into sub-directories." + (interactive "") + (let ((+ivy--file-search-recursion-p (not bang))) + (+ivy:grep beg end query t default-directory))) + ;;;###autoload (autoload '+ivy:ag-cwd "completion/ivy/autoload/evil" nil t) (evil-define-operator +ivy:ag-cwd (beg end query &optional bang) "The same as :ag, but searches the current directory. If BANG, don't recurse diff --git a/modules/config/default/+evil-commands.el b/modules/config/default/+evil-commands.el index 79e3c0e9d..64a9a0636 100644 --- a/modules/config/default/+evil-commands.el +++ b/modules/config/default/+evil-commands.el @@ -78,6 +78,8 @@ (ex! "agc[wd]" #'+ivy:ag-cwd) (ex! "rg" #'+ivy:rg) (ex! "rgc[wd]" #'+ivy:rg-cwd) + (ex! "grep" #'+ivy:grep) + (ex! "grepc[wd]" #'+ivy:grep-cwd) (ex! "sw[iper]" #'+ivy:swiper) (ex! "todo" #'+ivy:todo)) ((featurep! :completion helm)