Enable users to interactively specify extra switches along with the search pattern when invoking counsel-ag.
For example, M-x counsel-ag:
[~/.emacs.d] ag: --elisp --ignore site-lisp -- let
UI
Assume counsel-ag-command is set to ag --nocolor --nogroup.
It behaves the same as before when the query starts with anything but a dash: M-x counsel-ag abc ↵ Produces ag --nocolor --nogroup abc
Regex are escaped: M-x counsel-ag abc[^d]. ↵ Produces ag --nocolor --nogroup abc\[\^d\].
Starting with - or -- passes the text as switches until a --: M-x counsel-ag --elisp -- abc ↵ Produces ag --nocolor --nogroup --elisp abc
Initial dashes need to be escaped if they are not switches: M-x counsel-ag \-abc ↵ Produces ag --nocolor --nogroup \\-abc
Switches are not escaped. Queries are: M-x counsel-ag --elisp -- abc[^d]. ↵ Produces ag --nocolor --nogroup --elisp abc\[\^d\].
Using a prefix argument behaves the same as before: C-u M-x counsel-ag ag --nocolor --nogroup --elisp ↵ abc ↵ Produces ag --nocolor --nogroup --elisp abc
File Mask
-t can apply builtin file masks to filter files, use rg --type-list to see all the builtin masks, e.g. M-x counsel-rg ↵ -t txt -- list to search “list” in all txt files.
--type-add can help to define custom file mask, e.g. --type-add 'foo:*.{foo,boo}' -t foo PATTERN.
Or, we can define custom search functions using the following format: