ripgrep 12.1.1
-SIMD -AVX (compiled)
+SIMD +AVX (runtime)
sudo pacman -S ripgrep
Arch Linux 5.9.10-arch1-1
rg fails to look for "-1", "->", etc.
this one works:
rg 'idea' .gitignore
this one doesn't:
rg '-1' .gitignore
_error: Found argument '-1' which wasn't expected, or isn't valid in this context_
Please see above.
The pattern is considered as an argument.
Looking for a pattern provided.
thanks to the colleague of mine, this opt parsing issue is not an rg issue
Right, and indeed, from the man page:
A regular expression used for searching. To match a pattern beginning with a dash, use the
-e/--regexp option.
Thanks! I was having a problem which is being resolved like this:
rg -F -- '-1'
Yes, that also works, because -- indicates the end of all non-positional arguments. Therefore, anything after -- is treated as a positional argument. Otherwise, when you use -x, there is ambiguity between whether -x is a flag or a positional argument.
Also, the -F flag is unnecessary in this case. rg -- -1 is equivalent. As is rg -e -1.
These are standard problems in Unix command line tools. The -- trick is the most common work-around. The -e trick is more specific to grep-like tools, but does work with GNU grep as well.
Most helpful comment
Yes, that also works, because
--indicates the end of all non-positional arguments. Therefore, anything after--is treated as a positional argument. Otherwise, when you use-x, there is ambiguity between whether-xis a flag or a positional argument.Also, the
-Fflag is unnecessary in this case.rg -- -1is equivalent. As isrg -e -1.These are standard problems in Unix command line tools. The
--trick is the most common work-around. The-etrick is more specific to grep-like tools, but does work with GNU grep as well.