Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for persistent config #772

Merged
merged 6 commits into from
Feb 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 9 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ members = [ "grep", "globset", "ignore", "termcolor", "wincolor" ]
[dependencies]
atty = "0.2.2"
bytecount = "0.3.1"
clap = "2.26"
encoding_rs = "0.7"
env_logger = { version = "0.4", default-features = false }
grep = { version = "0.1.7", path = "grep" }
ignore = { version = "0.3.1", path = "ignore" }
lazy_static = "1"
libc = "0.2"
log = "0.3"
log = "0.4"
memchr = "2"
memmap = "0.6"
num_cpus = "1"
Expand All @@ -51,14 +49,23 @@ same-file = "1"
termcolor = { version = "0.3.3", path = "termcolor" }
globset = { version = "0.2.1", path = "globset" }

[dependencies.clap]
version = "2.26"
default-features = false
features = ["suggestions", "color"]

[target.'cfg(windows)'.dependencies.winapi]
version = "0.3"
features = ["std", "winnt"]

[build-dependencies]
clap = "2.26"
lazy_static = "1"

[build-dependencies.clap]
version = "2.26"
default-features = false
features = ["suggestions", "color"]

[features]
avx-accel = ["bytecount/avx-accel"]
simd-accel = [
Expand Down
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,50 @@ extensions.
The syntax supported is
[documented as part of Rust's regex library](https://doc.rust-lang.org/regex/regex/index.html#syntax).

### 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 completions

Shell completion files are included in the release tarball for Bash, Fish, Zsh
Expand Down
23 changes: 22 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern crate lazy_static;

use std::env;
use std::fs;
use std::process;

use clap::Shell;

Expand All @@ -13,14 +14,34 @@ use clap::Shell;
mod app;

fn main() {
// OUT_DIR is set by Cargo and it's where any additional build artifacts
// are written.
let outdir = match env::var_os("OUT_DIR") {
None => return,
Some(outdir) => outdir,
None => {
eprintln!(
"OUT_DIR environment variable not defined. \
Please file a bug: \
https://github.com/BurntSushi/ripgrep/issues/new");
process::exit(1);
}
};
fs::create_dir_all(&outdir).unwrap();

// Use clap to build completion files.
let mut app = app::app();
app.gen_completions("rg", Shell::Bash, &outdir);
app.gen_completions("rg", Shell::Fish, &outdir);
app.gen_completions("rg", Shell::PowerShell, &outdir);
// Note that we do not use clap's support for zsh. Instead, zsh completions
// are manually maintained in `complete/_rg`.

// Make the current git hash available to the build.
let result = process::Command::new("git")
.args(&["rev-parse", "--short=10", "HEAD"])
.output();
if let Ok(output) = result {
let hash = String::from_utf8_lossy(&output.stdout);
println!("cargo:rustc-env=RIPGREP_BUILD_GIT_HASH={}", hash);
}
}
1 change: 1 addition & 0 deletions complete/_rg
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ _rg() {
'(--mmap --no-mmap)--mmap[search using memory maps when possible]'
'(-H --with-filename --no-filename)--no-filename[suppress all file names]'
"(-p --heading --pretty --vimgrep)--no-heading[don't group matches by file name]"
"--no-config[don't load configuration files]"
"(--no-ignore-parent)--no-ignore[don't respect ignore files]"
"--no-ignore-parent[don't respect ignore files in parent directories]"
"--no-ignore-vcs[don't respect version control ignore files]"
Expand Down
82 changes: 82 additions & 0 deletions doc/rg.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Loading