Ripgrep: .ripgreprc & glob patterns

Created on 24 May 2018  Â·  7Comments  Â·  Source: BurntSushi/ripgrep

What version of ripgrep are you using?

ripgrep 0.8.1
-SIMD -AVX

How did you install ripgrep?

Homebrew

What operating system are you using ripgrep on?

macOS 10.13.4

Describe your question, feature request, or bug.

I'm trying to add a global .ripgreprc file with the following but I can't seem to make it work with --glob

--smart-case
--follow
--glob "!.git/*"
--glob "!node_modules/*"

This returns

error: Found argument '--glob "!.git/*"' which wasn't expected, or isn't valid in this context
        Did you mean --glob?

USAGE:

    rg [OPTIONS] PATTERN [PATH ...]
    rg [OPTIONS] [-e PATTERN ...] [-f FILE ...] [PATH ...]
    rg [OPTIONS] --files [PATH ...]
    rg [OPTIONS] --type-list

For more information try --help

I also tried

--smart-case
--follow
--glob 
"!.git/*"
--glob 
"!node_modules/*"

this returns

No files were searched, which means ripgrep probably applied a filter you didn't expect. Try running again with --debug.

So how can I do this?

Most helpful comment

Each line in the ripgreprc is an individual argument, and there is no special handling of quoting or escaping or anything else. (If you're familiar with C, each line is basically an element of the argv array to execve() or similar.) The only special cases are (1) leading and trailing white space is trimmed from each line, and (2) lines with a leading # are ignored as comments.

So you'd want to write your glob lines like either

--glob=!node_modules/*

or

!node_modules/*

All 7 comments

Each line in the ripgreprc is an individual argument, and there is no special handling of quoting or escaping or anything else. (If you're familiar with C, each line is basically an element of the argv array to execve() or similar.) The only special cases are (1) leading and trailing white space is trimmed from each line, and (2) lines with a leading # are ignored as comments.

So you'd want to write your glob lines like either

--glob=!node_modules/*

or

!node_modules/*

I assumed I need to keep the quotes, thanks very much @okdana

Thanks @okdana!

@ahmedelgabri Note that the format is document in both the man page and in the guide.

@BurntSushi I did read the help but I didn't see any examples besides simple flags

Every line is a shell argument, after trimming ASCII whitespace.

When I read this I interpreted it as --glob "!git/*" not as --glob=!git/*

@ahmedelgabri Does the --type-add example in the guide clarify things? If you think an explicit example with globs would help, then that sounds like a nice addition too.

It’s useful indeed but I honestly I only checked the manpage & searched for anything related to RIPGREP_CONFIG_PATH

But I’d add an example for glob too & have the same examples in the manpage & the guide. I can open a PR tomorrow for this if you want.

Sent from my iPhone


From: Andrew Gallant notifications@github.com
Sent: Friday, May 25, 2018 12:40:40 AM
To: BurntSushi/ripgrep
Cc: Ahmed El Gabri; Mention
Subject: Re: [BurntSushi/ripgrep] .ripgreprc & glob patterns (#927)

@ahmedelgabrihttps://github.com/ahmedelgabri Does the --type-add example in the guide clarify things? If you think an explicit example with globs would help, then that sounds like a nice addition too.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/BurntSushi/ripgrep/issues/927#issuecomment-391887752, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAD5hMhR9P8a2_Wfu9-aIqs1VqAEzK-hks5t1zbogaJpZM4UNBV2.

@ahmedelgabri SGTM! Much appreciated.

Was this page helpful?
0 / 5 - 0 ratings