added docs and migrated name to rgs, migrated repo, added squash-lines feature
Some checks failed
ci / test (beta, ubuntu-latest, beta) (pull_request) Has been cancelled
ci / test (macos, macos-latest, nightly) (pull_request) Has been cancelled
ci / test (nightly, ubuntu-latest, nightly) (pull_request) Has been cancelled
ci / test (pinned, ubuntu-latest, 1.85.0) (pull_request) Has been cancelled
ci / test (stable, ubuntu-latest, stable) (pull_request) Has been cancelled
ci / test (stable-aarch64, ubuntu-latest, stable, aarch64-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-arm-gnueabihf, ubuntu-latest, stable, armv7-unknown-linux-gnueabihf) (pull_request) Has been cancelled
ci / test (stable-arm-musleabi, ubuntu-latest, stable, armv7-unknown-linux-musleabi) (pull_request) Has been cancelled
ci / test (stable-arm-musleabihf, ubuntu-latest, stable, armv7-unknown-linux-musleabihf) (pull_request) Has been cancelled
ci / test (stable-musl, ubuntu-latest, stable, x86_64-unknown-linux-musl) (pull_request) Has been cancelled
ci / test (stable-powerpc64, ubuntu-latest, stable, powerpc64-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-riscv64, ubuntu-latest, stable, riscv64gc-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-s390x, ubuntu-latest, stable, s390x-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-x86, ubuntu-latest, stable, i686-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (win-gnu, windows-latest, nightly-x86_64-gnu) (pull_request) Has been cancelled
ci / test (win-msvc, windows-latest, nightly) (pull_request) Has been cancelled
ci / test (winaarch64-msvc, windows-11-arm, nightly) (pull_request) Has been cancelled
ci / wasm (pull_request) Has been cancelled
ci / rustfmt (pull_request) Has been cancelled
ci / docs (pull_request) Has been cancelled
ci / Compile Fuzz Test Targets (pull_request) Has been cancelled
Some checks failed
ci / test (beta, ubuntu-latest, beta) (pull_request) Has been cancelled
ci / test (macos, macos-latest, nightly) (pull_request) Has been cancelled
ci / test (nightly, ubuntu-latest, nightly) (pull_request) Has been cancelled
ci / test (pinned, ubuntu-latest, 1.85.0) (pull_request) Has been cancelled
ci / test (stable, ubuntu-latest, stable) (pull_request) Has been cancelled
ci / test (stable-aarch64, ubuntu-latest, stable, aarch64-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-arm-gnueabihf, ubuntu-latest, stable, armv7-unknown-linux-gnueabihf) (pull_request) Has been cancelled
ci / test (stable-arm-musleabi, ubuntu-latest, stable, armv7-unknown-linux-musleabi) (pull_request) Has been cancelled
ci / test (stable-arm-musleabihf, ubuntu-latest, stable, armv7-unknown-linux-musleabihf) (pull_request) Has been cancelled
ci / test (stable-musl, ubuntu-latest, stable, x86_64-unknown-linux-musl) (pull_request) Has been cancelled
ci / test (stable-powerpc64, ubuntu-latest, stable, powerpc64-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-riscv64, ubuntu-latest, stable, riscv64gc-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-s390x, ubuntu-latest, stable, s390x-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-x86, ubuntu-latest, stable, i686-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (win-gnu, windows-latest, nightly-x86_64-gnu) (pull_request) Has been cancelled
ci / test (win-msvc, windows-latest, nightly) (pull_request) Has been cancelled
ci / test (winaarch64-msvc, windows-11-arm, nightly) (pull_request) Has been cancelled
ci / wasm (pull_request) Has been cancelled
ci / rustfmt (pull_request) Has been cancelled
ci / docs (pull_request) Has been cancelled
ci / Compile Fuzz Test Targets (pull_request) Has been cancelled
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#compdef rg
|
||||
#compdef rgs
|
||||
|
||||
##
|
||||
# zsh completion function for ripgrep
|
||||
# zsh completion function for rgs
|
||||
#
|
||||
# Run ci/test-complete after building to ensure that the options supported by
|
||||
# this function stay in synch with the `rg` binary.
|
||||
@@ -212,7 +212,7 @@ _rg() {
|
||||
|
||||
+ '(multiline)' # Multiline options
|
||||
{-U,--multiline}'[permit matching across multiple lines]'
|
||||
'--multiline-window=[limit multiline matches to NUM lines (with -U)]:number of lines'
|
||||
{-W+,--multiline-window=}'[limit multiline matches to NUM lines (with -U enabled implicitly)]:number of lines'
|
||||
$no'(multiline-dotall)--no-multiline[restrict matches to at most one line each]'
|
||||
|
||||
+ '(multiline-dotall)' # Multiline DOTALL options
|
||||
@@ -282,6 +282,10 @@ _rg() {
|
||||
+ '(threads)' # Thread-count options
|
||||
'(sort)'{-j+,--threads=}'[specify approximate number of threads to use]:number of threads'
|
||||
|
||||
+ '(squash)' # Squash options
|
||||
'--squash[squash contiguous whitespace into a single space]'
|
||||
'--squash-nl-only[squash new lines into a single space]'
|
||||
|
||||
+ '(trim)' # Trim options
|
||||
'--trim[trim any ASCII whitespace prefix from each line]'
|
||||
$no"--no-trim[don't trim ASCII whitespace prefix from each line]"
|
||||
@@ -26,7 +26,7 @@ pub(crate) fn generate() -> String {
|
||||
})
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n");
|
||||
include_str!("rg.zsh")
|
||||
include_str!("rgs.zsh")
|
||||
.replace("!ENCODINGS!", super::ENCODINGS.trim_end())
|
||||
.replace("!HYPERLINK_ALIASES!", &hyperlink_alias_descriptions)
|
||||
}
|
||||
|
||||
@@ -134,6 +134,8 @@ pub(super) const FLAGS: &[&dyn Flag] = &[
|
||||
&Text,
|
||||
&Threads,
|
||||
&Trace,
|
||||
&Squash,
|
||||
&SquashNlOnly,
|
||||
&Trim,
|
||||
&Type,
|
||||
&TypeNot,
|
||||
@@ -4187,7 +4189,14 @@ This overrides the \flag{stop-on-nonmatch} flag.
|
||||
}
|
||||
|
||||
fn update(&self, v: FlagValue, args: &mut LowArgs) -> anyhow::Result<()> {
|
||||
args.multiline = v.unwrap_switch();
|
||||
let enabled = v.unwrap_switch();
|
||||
if !enabled && args.multiline_window.is_some() {
|
||||
anyhow::bail!(
|
||||
"--no-multiline cannot be used with --multiline-window \
|
||||
(which implicitly enables --multiline)"
|
||||
);
|
||||
}
|
||||
args.multiline = enabled;
|
||||
if args.multiline {
|
||||
args.stop_on_nonmatch = false;
|
||||
}
|
||||
@@ -4219,6 +4228,9 @@ impl Flag for MultilineWindow {
|
||||
fn is_switch(&self) -> bool {
|
||||
false
|
||||
}
|
||||
fn name_short(&self) -> Option<u8> {
|
||||
Some(b'W')
|
||||
}
|
||||
fn name_long(&self) -> &'static str {
|
||||
"multiline-window"
|
||||
}
|
||||
@@ -4236,7 +4248,7 @@ impl Flag for MultilineWindow {
|
||||
Limit the maximum number of lines that a multiline match may span to
|
||||
\fINUM\fP (use \fB--multiline-window=\fP\fINUM\fP).
|
||||
.sp
|
||||
This flag requires \flag{multiline}. Matches are found as if the file being
|
||||
This flag implicitly enables \flag{multiline}. Matches are found as if the file being
|
||||
searched were limited to \fINUM\fP lines at a time, which can prevent
|
||||
unintended long matches while still enabling multi-line searching.
|
||||
.sp
|
||||
@@ -4250,6 +4262,7 @@ The value of \fINUM\fP must be at least 1.
|
||||
anyhow::bail!("--multiline-window must be at least 1");
|
||||
}
|
||||
args.multiline_window = Some(lines);
|
||||
args.multiline = true;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -4262,6 +4275,11 @@ fn test_multiline_window() {
|
||||
|
||||
let args = parse_low_raw(["--multiline-window=2"]).unwrap();
|
||||
assert_eq!(Some(2), args.multiline_window);
|
||||
assert_eq!(true, args.multiline);
|
||||
|
||||
let args = parse_low_raw(["-W", "3"]).unwrap();
|
||||
assert_eq!(Some(3), args.multiline_window);
|
||||
assert_eq!(true, args.multiline);
|
||||
}
|
||||
|
||||
/// --multiline-dotall
|
||||
@@ -6866,6 +6884,88 @@ fn test_trace() {
|
||||
assert_eq!(Some(LoggingMode::Trace), args.logging);
|
||||
}
|
||||
|
||||
/// --squash
|
||||
#[derive(Debug)]
|
||||
struct Squash;
|
||||
|
||||
impl Flag for Squash {
|
||||
fn is_switch(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn name_long(&self) -> &'static str {
|
||||
"squash"
|
||||
}
|
||||
fn doc_category(&self) -> Category {
|
||||
Category::Output
|
||||
}
|
||||
fn doc_short(&self) -> &'static str {
|
||||
r"Squash contiguous whitespace in output to a single space."
|
||||
}
|
||||
fn doc_long(&self) -> &'static str {
|
||||
r#"
|
||||
Squash any contiguous Unicode whitespace (including new lines) into a single
|
||||
ASCII space when printing matches.
|
||||
"#
|
||||
}
|
||||
|
||||
fn update(&self, v: FlagValue, args: &mut LowArgs) -> anyhow::Result<()> {
|
||||
assert!(v.unwrap_switch(), "--squash can only be enabled");
|
||||
args.squash = grep::printer::SquashMode::Whitespace;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
fn test_squash() {
|
||||
let args = parse_low_raw(None::<&str>).unwrap();
|
||||
assert_eq!(grep::printer::SquashMode::None, args.squash);
|
||||
|
||||
let args = parse_low_raw(["--squash"]).unwrap();
|
||||
assert_eq!(grep::printer::SquashMode::Whitespace, args.squash);
|
||||
}
|
||||
|
||||
/// --squash-nl-only
|
||||
#[derive(Debug)]
|
||||
struct SquashNlOnly;
|
||||
|
||||
impl Flag for SquashNlOnly {
|
||||
fn is_switch(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn name_long(&self) -> &'static str {
|
||||
"squash-nl-only"
|
||||
}
|
||||
fn doc_category(&self) -> Category {
|
||||
Category::Output
|
||||
}
|
||||
fn doc_short(&self) -> &'static str {
|
||||
r"Squash new lines into spaces in output."
|
||||
}
|
||||
fn doc_long(&self) -> &'static str {
|
||||
r#"
|
||||
Squash contiguous line terminators into a single ASCII space when printing
|
||||
matches. Other whitespace is preserved.
|
||||
"#
|
||||
}
|
||||
|
||||
fn update(&self, v: FlagValue, args: &mut LowArgs) -> anyhow::Result<()> {
|
||||
assert!(v.unwrap_switch(), "--squash-nl-only can only be enabled");
|
||||
args.squash = grep::printer::SquashMode::Newlines;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
fn test_squash_nl_only() {
|
||||
let args = parse_low_raw(None::<&str>).unwrap();
|
||||
assert_eq!(grep::printer::SquashMode::None, args.squash);
|
||||
|
||||
let args = parse_low_raw(["--squash-nl-only"]).unwrap();
|
||||
assert_eq!(grep::printer::SquashMode::Newlines, args.squash);
|
||||
}
|
||||
|
||||
/// --trim
|
||||
#[derive(Debug)]
|
||||
struct Trim;
|
||||
|
||||
@@ -9,7 +9,7 @@ use std::{
|
||||
|
||||
use {
|
||||
bstr::BString,
|
||||
grep::printer::{ColorSpecs, SummaryKind},
|
||||
grep::printer::{ColorSpecs, SquashMode, SummaryKind},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -100,6 +100,7 @@ pub(crate) struct HiArgs {
|
||||
sort: Option<SortMode>,
|
||||
stats: Option<grep::printer::Stats>,
|
||||
stop_on_nonmatch: bool,
|
||||
squash: SquashMode,
|
||||
threads: usize,
|
||||
trim: bool,
|
||||
types: ignore::types::Types,
|
||||
@@ -142,9 +143,6 @@ impl HiArgs {
|
||||
}
|
||||
|
||||
let mut state = State::new()?;
|
||||
if low.multiline_window.is_some() && !low.multiline {
|
||||
anyhow::bail!("--multiline-window requires --multiline");
|
||||
}
|
||||
let patterns = Patterns::from_low_args(&mut state, &mut low)?;
|
||||
let paths = Paths::from_low_args(&mut state, &patterns, &mut low)?;
|
||||
|
||||
@@ -320,6 +318,7 @@ impl HiArgs {
|
||||
sort: low.sort,
|
||||
stats,
|
||||
stop_on_nonmatch: low.stop_on_nonmatch,
|
||||
squash: low.squash,
|
||||
threads,
|
||||
trim: low.trim,
|
||||
types,
|
||||
@@ -632,6 +631,7 @@ impl HiArgs {
|
||||
.per_match_one_line(true)
|
||||
.per_match(self.vimgrep)
|
||||
.replacement(self.replace.clone().map(|r| r.into()))
|
||||
.squash(self.squash)
|
||||
.separator_context(self.context_separator.clone().into_bytes())
|
||||
.separator_field_context(
|
||||
self.field_context_separator.clone().into_bytes(),
|
||||
|
||||
@@ -9,7 +9,7 @@ use std::{
|
||||
|
||||
use {
|
||||
bstr::{BString, ByteVec},
|
||||
grep::printer::{HyperlinkFormat, UserColorSpec},
|
||||
grep::printer::{HyperlinkFormat, SquashMode, UserColorSpec},
|
||||
};
|
||||
|
||||
/// A collection of "low level" arguments.
|
||||
@@ -103,6 +103,7 @@ pub(crate) struct LowArgs {
|
||||
pub(crate) sort: Option<SortMode>,
|
||||
pub(crate) stats: bool,
|
||||
pub(crate) stop_on_nonmatch: bool,
|
||||
pub(crate) squash: SquashMode,
|
||||
pub(crate) threads: Option<usize>,
|
||||
pub(crate) trim: bool,
|
||||
pub(crate) type_changes: Vec<TypeChange>,
|
||||
|
||||
Reference in New Issue
Block a user