mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-01-21 04:38:36 +01:00
batgrep: add flag to disable separators between files
This commit is contained in:
parent
7803ecaba1
commit
8ad00bd978
@ -31,6 +31,7 @@ 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 |
|
||||
|
||||
The following options are passed directly to ripgrep, and are not handled by this script.
|
||||
|
||||
|
@ -38,6 +38,7 @@ OPT_SNIP=""
|
||||
OPT_HIGHLIGHT=true
|
||||
OPT_SEARCH_PATTERN=false
|
||||
OPT_FIXED_STRINGS=false
|
||||
OPT_NO_SEPARATOR=false
|
||||
BAT_STYLE="${BAT_STYLE:-header,numbers}"
|
||||
|
||||
# Set options based on the bat version.
|
||||
@ -117,6 +118,7 @@ while shiftopt; do
|
||||
--no-highlight) OPT_HIGHLIGHT=false ;;
|
||||
-p | --search-pattern) OPT_SEARCH_PATTERN=true ;;
|
||||
--no-search-pattern) OPT_SEARCH_PATTERN=false ;;
|
||||
--no-separator) OPT_NO_SEPARATOR=true ;;
|
||||
|
||||
# Option forwarding
|
||||
--rg:*) {
|
||||
@ -214,6 +216,12 @@ main() {
|
||||
LAST_LH=()
|
||||
LAST_FILE=''
|
||||
READ_FROM_STDIN=false
|
||||
NO_SEPARATOR="$OPT_NO_SEPARATOR"
|
||||
|
||||
if [[ "$BAT_STYLE" = *grid* ]]; then
|
||||
NO_SEPARATOR=true
|
||||
fi
|
||||
|
||||
|
||||
# If we found no files being provided and STDIN to not be attached to a tty,
|
||||
# we capture STDIN to a variable. This variable will later be written to
|
||||
@ -248,7 +256,7 @@ main() {
|
||||
[[ -z "$LAST_FILE" ]] && return 0
|
||||
|
||||
# Print the separator.
|
||||
if ! [[ "$BAT_STYLE" = *grid* ]]; then
|
||||
if ! "$NO_SEPARATOR"; then
|
||||
"$FIRST_PRINT" && echo "$SEP"
|
||||
fi
|
||||
FIRST_PRINT=false
|
||||
@ -263,7 +271,7 @@ main() {
|
||||
"$LAST_FILE"
|
||||
|
||||
# Print the separator.
|
||||
if ! [[ "$BAT_STYLE" = *grid* ]]; then
|
||||
if ! "$NO_SEPARATOR"; then
|
||||
echo "$SEP"
|
||||
fi
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
File: [1mfile.txt[0m
|
||||
[38;5;238m 1[0m [48;5;236;38;5;231mcat[0m[48;5;236m [0m
|
||||
[38;5;238m 2[0m [38;5;231mdog[0m
|
||||
[38;5;238m 3[0m [48;5;236;38;5;231mcar[0m[48;5;236m [0m
|
||||
[38;5;238m 4[0m [38;5;231mfrog[0m
|
||||
[38;5;238m 5[0m [38;5;231mfox[0m
|
@ -114,3 +114,13 @@ test:respects_bat_style() {
|
||||
|
||||
BAT_STYLE="grid" batgrep "ca" file.txt --color=always
|
||||
}
|
||||
|
||||
test:output_without_separator() {
|
||||
description "Snapshot test for output without separator"
|
||||
snapshot stdout
|
||||
snapshot stderr
|
||||
|
||||
require_rg
|
||||
|
||||
batgrep "ca" file.txt --no-separator --color=always
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user