Ripgrep: Fails to look for "-1", "->", etc.

Created on 24 Nov 2020  路  4Comments  路  Source: BurntSushi/ripgrep

What version of ripgrep are you using?

ripgrep 12.1.1
-SIMD -AVX (compiled)
+SIMD +AVX (runtime)

How did you install ripgrep?

sudo pacman -S ripgrep

What operating system are you using ripgrep on?

Arch Linux 5.9.10-arch1-1

Describe your bug.

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_

What are the steps to reproduce the behavior?

Please see above.

What is the actual behavior?

The pattern is considered as an argument.

What is the expected behavior?

Looking for a pattern provided.

invalid

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

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

daxim picture daxim  路  3Comments

andschwa picture andschwa  路  3Comments

crumblingstatue picture crumblingstatue  路  3Comments

hauleth picture hauleth  路  3Comments

Offpics picture Offpics  路  3Comments