batgrep: Add support for ripgrep-all

To use `ripgrep-all`, add the `--rga` flag when running batgrep.
This commit is contained in:
Ethan P. 2024-02-12 01:16:26 -08:00
parent 82911b5b7b
commit 5011f0709e
No known key found for this signature in database
GPG Key ID: 1BA2A0CC7C22B854
3 changed files with 21 additions and 5 deletions

View File

@ -31,7 +31,8 @@ Search through files or directories looking for matching regular expressions (or
| | `--paging=["never"/"always"]`| Enable/disable paging. |
| | `--pager=[PAGER]` | Specify the pager to use. |
| | `--terminal-width=[COLS]` | Generate output for the specified terminal width. |
| | `--no-separator` | Disable printing separator between files |
| | `--no-separator` | Disable printing separator between files. |
| | `--rga` | Use `ripgrep-all` instead of `ripgrep`. |
The following options are passed directly to ripgrep, and are not handled by this script.

View File

@ -97,7 +97,10 @@ Options:
Generate output for the specified terminal width.
--no-separator:
Disable printing separator between files
Disable printing separator between files.
--rga:
Use ripgrep-all instead of ripgrep.
Options passed directly to ripgrep:
-F, --fixed-strings
@ -141,6 +144,7 @@ EOF
# -----------------------------------------------------------------------------
# Options:
# -----------------------------------------------------------------------------
RIPGREP="$EXECUTABLE_RIPGREP"
RG_ARGS=()
BAT_ARGS=()
PATTERN=""
@ -252,6 +256,14 @@ while shiftopt; do
-p | --search-pattern) OPT_SEARCH_PATTERN=true ;;
--no-search-pattern) OPT_SEARCH_PATTERN=false ;;
--no-separator) OPT_NO_SEPARATOR=true ;;
--rga) {
if ! rga --version | grep 'ripgrep-all' &>/dev/null; then
printc "%{RED}%s: option '--rga' requires ripgrep-all to be installed%{CLEAR}\n" "$PROGRAM" 1>&2
exit 1
fi
RIPGREP='rga'
};;
# Option forwarding
--rg:*) {
@ -377,10 +389,10 @@ main() {
)
if "$READ_FROM_STDIN"; then
"$EXECUTABLE_RIPGREP" "${COMMON_RG_ARGS[@]}" <<< "$STDIN_DATA"
"$RIPGREP" "${COMMON_RG_ARGS[@]}" <<< "$STDIN_DATA"
return $?
else
"$EXECUTABLE_RIPGREP" "${COMMON_RG_ARGS[@]}"
"$RIPGREP" "${COMMON_RG_ARGS[@]}"
return $?
fi
}

View File

@ -63,7 +63,10 @@ Options:
Generate output for the specified terminal width.
--no-separator:
Disable printing separator between files
Disable printing separator between files.
--rga:
Use ripgrep-all instead of ripgrep.
Options passed directly to ripgrep:
-F, --fixed-strings