1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-06-14 22:15:13 +02:00

config: add persistent configuration

This commit adds support for reading configuration files that change
ripgrep's default behavior. The format of the configuration file is an
"rc" style and is very simple. It is defined by two rules:

  1. Every line is a shell argument, after trimming ASCII whitespace.
  2. Lines starting with '#' (optionally preceded by any amount of
     ASCII whitespace) are ignored.

ripgrep will look for a single configuration file if and only if the
RIPGREP_CONFIG_PATH environment variable is set and is non-empty.
ripgrep will parse shell arguments from this file on startup and will
behave as if the arguments in this file were prepended to any explicit
arguments given to ripgrep on the command line.

For example, if your ripgreprc file contained a single line:

    --smart-case

then the following command

    RIPGREP_CONFIG_PATH=wherever/.ripgreprc rg foo

would behave identically to the following command

    rg --smart-case foo

This commit also adds a new flag, --no-config, that when present will
suppress any and all support for configuration. This includes any future
support for auto-loading configuration files from pre-determined paths
(which this commit does not add).

Conflicts between configuration files and explicit arguments are handled
exactly like conflicts in the same command line invocation. That is,
this command:

    RIPGREP_CONFIG_PATH=wherever/.ripgreprc rg foo --case-sensitive

is exactly equivalent to

    rg --smart-case foo --case-sensitive

in which case, the --case-sensitive flag would override the --smart-case
flag.

Closes #196
This commit is contained in:
Andrew Gallant
2018-02-03 20:33:52 -05:00
parent d83bab4d3f
commit c57d0fb4e8
10 changed files with 460 additions and 5 deletions

View File

@ -403,6 +403,17 @@ context related options.)
.RS
.RE
.TP
.B \-\-no\-config
Never read configuration files.
When this flag is present, ripgrep will not respect the
RIPGREP_CONFIG_PATH environment variable.
.RS
.PP
If ripgrep ever grows a feature to automatically read configuration
files in pre\-defined locations, then this flag will also disable that
behavior as well.
.RE
.TP
.B \-\-no\-messages
Suppress all error messages.
.RS
@ -597,6 +608,77 @@ ripgrep.
Note that this must be passed to every invocation of rg.
.RS
.RE
.SH CONFIGURATION FILES
.PP
ripgrep supports reading configuration files that change ripgrep\[aq]s
default behavior.
The format of the configuration file is an "rc" style and is very
simple.
It is defined by two rules:
.IP
.nf
\f[C]
1.\ Every\ line\ is\ a\ shell\ argument,\ after\ trimming\ ASCII\ whitespace.
2.\ Lines\ starting\ with\ \[aq]#\[aq]\ (optionally\ preceded\ by\ any\ amount\ of
\ \ \ ASCII\ whitespace)\ are\ ignored.
\f[]
.fi
.PP
ripgrep will look for a single configuration file if and only if the
RIPGREP_CONFIG_PATH environment variable is set and is non\-empty.
ripgrep will parse shell arguments from this file on startup and will
behave as if the arguments in this file were prepended to any explicit
arguments given to ripgrep on the command line.
.PP
For example, if your ripgreprc file contained a single line:
.IP
.nf
\f[C]
\-\-smart\-case
\f[]
.fi
.PP
then the following command
.IP
.nf
\f[C]
RIPGREP_CONFIG_PATH=wherever/.ripgreprc\ rg\ foo
\f[]
.fi
.PP
would behave identically to the following command
.IP
.nf
\f[C]
rg\ \-\-smart\-case\ foo
\f[]
.fi
.PP
ripgrep also provides a flag, \-\-no\-config, that when present will
suppress any and all support for configuration.
This includes any future support for auto\-loading configuration files
from pre\-determined paths.
.PP
Conflicts between configuration files and explicit arguments are handled
exactly like conflicts in the same command line invocation.
That is, this command:
.IP
.nf
\f[C]
RIPGREP_CONFIG_PATH=wherever/.ripgreprc\ rg\ foo\ \-\-case\-sensitive
\f[]
.fi
.PP
is exactly equivalent to
.IP
.nf
\f[C]
rg\ \-\-smart\-case\ foo\ \-\-case\-sensitive
\f[]
.fi
.PP
in which case, the \-\-case\-sensitive flag would override the
\-\-smart\-case flag.
.SH SHELL COMPLETION
.PP
Shell completion files are included in the release tarball for Bash,

View File

@ -268,6 +268,14 @@ Project home page: https://github.com/BurntSushi/ripgrep
when ripgrep thinks it will be faster. (Note that mmap searching
doesn't currently support the various context related options.)
--no-config
: Never read configuration files. When this flag is present, ripgrep will not
respect the RIPGREP_CONFIG_PATH environment variable.
If ripgrep ever grows a feature to automatically read configuration files
in pre-defined locations, then this flag will also disable that behavior as
well.
--no-messages
: Suppress all error messages.
@ -392,6 +400,51 @@ Project home page: https://github.com/BurntSushi/ripgrep
the default type definitions that are found inside of ripgrep. Note
that this must be passed to every invocation of rg.
# CONFIGURATION FILES
ripgrep supports reading configuration files that change
ripgrep's default behavior. The format of the configuration file is an
"rc" style and is very simple. It is defined by two rules:
1. Every line is a shell argument, after trimming ASCII whitespace.
2. Lines starting with '#' (optionally preceded by any amount of
ASCII whitespace) are ignored.
ripgrep will look for a single configuration file if and only if the
RIPGREP_CONFIG_PATH environment variable is set and is non-empty.
ripgrep will parse shell arguments from this file on startup and will
behave as if the arguments in this file were prepended to any explicit
arguments given to ripgrep on the command line.
For example, if your ripgreprc file contained a single line:
--smart-case
then the following command
RIPGREP_CONFIG_PATH=wherever/.ripgreprc rg foo
would behave identically to the following command
rg --smart-case foo
ripgrep also provides a flag, --no-config, that when present will suppress
any and all support for configuration. This includes any future support
for auto-loading configuration files from pre-determined paths.
Conflicts between configuration files and explicit arguments are handled
exactly like conflicts in the same command line invocation. That is,
this command:
RIPGREP_CONFIG_PATH=wherever/.ripgreprc rg foo --case-sensitive
is exactly equivalent to
rg --smart-case foo --case-sensitive
in which case, the --case-sensitive flag would override the --smart-case
flag.
# SHELL COMPLETION
Shell completion files are included in the release tarball for Bash, Fish, Zsh