mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-06-20 11:47:43 +02:00
batgrep: Respect the BAT_STYLE environment variable (#54)
This commit is contained in:
parent
a526c7927b
commit
cae57be87b
@ -38,7 +38,7 @@ OPT_SNIP=""
|
||||
OPT_HIGHLIGHT=true
|
||||
OPT_SEARCH_PATTERN=false
|
||||
OPT_FIXED_STRINGS=false
|
||||
BAT_STYLE="header,numbers"
|
||||
BAT_STYLE="${BAT_STYLE:-header,numbers}"
|
||||
|
||||
# Set options based on the bat version.
|
||||
if version_compare "$(bat_version)" -gt "0.12"; then
|
||||
@ -246,7 +246,9 @@ main() {
|
||||
[[ -z "$LAST_FILE" ]] && return 0
|
||||
|
||||
# Print the separator.
|
||||
"$FIRST_PRINT" && echo "$SEP"
|
||||
if ! [[ "$BAT_STYLE" = *grid* ]]; then
|
||||
"$FIRST_PRINT" && echo "$SEP"
|
||||
fi
|
||||
FIRST_PRINT=false
|
||||
|
||||
# Print the file.
|
||||
@ -259,7 +261,9 @@ main() {
|
||||
"$LAST_FILE"
|
||||
|
||||
# Print the separator.
|
||||
echo "$SEP"
|
||||
if ! [[ "$BAT_STYLE" = *grid* ]]; then
|
||||
echo "$SEP"
|
||||
fi
|
||||
}
|
||||
|
||||
do_print_from_file_or_stdin() {
|
||||
|
@ -0,0 +1,7 @@
|
||||
[38;5;238m────────────────────────────────────────────────────────────────────────────────[0m
|
||||
[48;5;236;38;5;231mcat[0m[48;5;236m [0m
|
||||
[38;5;231mdog[0m
|
||||
[48;5;236;38;5;231mcar[0m[48;5;236m [0m
|
||||
[38;5;231mfrog[0m
|
||||
[38;5;231mfox[0m
|
||||
[38;5;238m────────────────────────────────────────────────────────────────────────────────[0m
|
@ -2,6 +2,8 @@ HAS_RIPGREP=false
|
||||
|
||||
setup() {
|
||||
use_shim 'batgrep'
|
||||
|
||||
unset BAT_STYLE
|
||||
|
||||
if command -v rg &>/dev/null; then
|
||||
HAS_RIPGREP=true
|
||||
@ -102,3 +104,13 @@ test:search_from_stdin() {
|
||||
|
||||
cat file.txt | batgrep "^ca"
|
||||
}
|
||||
|
||||
test:respects_bat_style() {
|
||||
description "Should respect the BAT_STYLE variable."
|
||||
snapshot stdout
|
||||
snapshot stderr
|
||||
|
||||
require_rg
|
||||
|
||||
BAT_STYLE="grid" batgrep "ca" file.txt --color=always
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user