mirror of
https://github.com/eth-p/bat-extras.git
synced 2024-10-05 01:11:57 +02: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. |
|
| | `--paging=["never"/"always"]`| Enable/disable paging. |
|
||||||
| | `--pager=[PAGER]` | Specify the pager to use. |
|
| | `--pager=[PAGER]` | Specify the pager to use. |
|
||||||
| | `--terminal-width=[COLS]` | Generate output for the specified terminal width. |
|
| | `--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.
|
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_HIGHLIGHT=true
|
||||||
OPT_SEARCH_PATTERN=false
|
OPT_SEARCH_PATTERN=false
|
||||||
OPT_FIXED_STRINGS=false
|
OPT_FIXED_STRINGS=false
|
||||||
|
OPT_NO_SEPARATOR=false
|
||||||
BAT_STYLE="${BAT_STYLE:-header,numbers}"
|
BAT_STYLE="${BAT_STYLE:-header,numbers}"
|
||||||
|
|
||||||
# Set options based on the bat version.
|
# Set options based on the bat version.
|
||||||
@ -117,6 +118,7 @@ while shiftopt; do
|
|||||||
--no-highlight) OPT_HIGHLIGHT=false ;;
|
--no-highlight) OPT_HIGHLIGHT=false ;;
|
||||||
-p | --search-pattern) OPT_SEARCH_PATTERN=true ;;
|
-p | --search-pattern) OPT_SEARCH_PATTERN=true ;;
|
||||||
--no-search-pattern) OPT_SEARCH_PATTERN=false ;;
|
--no-search-pattern) OPT_SEARCH_PATTERN=false ;;
|
||||||
|
--no-separator) OPT_NO_SEPARATOR=true ;;
|
||||||
|
|
||||||
# Option forwarding
|
# Option forwarding
|
||||||
--rg:*) {
|
--rg:*) {
|
||||||
@ -214,6 +216,12 @@ main() {
|
|||||||
LAST_LH=()
|
LAST_LH=()
|
||||||
LAST_FILE=''
|
LAST_FILE=''
|
||||||
READ_FROM_STDIN=false
|
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,
|
# 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
|
# we capture STDIN to a variable. This variable will later be written to
|
||||||
@ -248,7 +256,7 @@ main() {
|
|||||||
[[ -z "$LAST_FILE" ]] && return 0
|
[[ -z "$LAST_FILE" ]] && return 0
|
||||||
|
|
||||||
# Print the separator.
|
# Print the separator.
|
||||||
if ! [[ "$BAT_STYLE" = *grid* ]]; then
|
if ! "$NO_SEPARATOR"; then
|
||||||
"$FIRST_PRINT" && echo "$SEP"
|
"$FIRST_PRINT" && echo "$SEP"
|
||||||
fi
|
fi
|
||||||
FIRST_PRINT=false
|
FIRST_PRINT=false
|
||||||
@ -263,7 +271,7 @@ main() {
|
|||||||
"$LAST_FILE"
|
"$LAST_FILE"
|
||||||
|
|
||||||
# Print the separator.
|
# Print the separator.
|
||||||
if ! [[ "$BAT_STYLE" = *grid* ]]; then
|
if ! "$NO_SEPARATOR"; then
|
||||||
echo "$SEP"
|
echo "$SEP"
|
||||||
fi
|
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
|
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