diff --git a/src/batgrep.sh b/src/batgrep.sh index 9df8a26..527815f 100755 --- a/src/batgrep.sh +++ b/src/batgrep.sh @@ -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() { diff --git a/test/snapshot/batgrep/test_respects_bat_style.stderr.snapshot b/test/snapshot/batgrep/test_respects_bat_style.stderr.snapshot new file mode 100644 index 0000000..e69de29 diff --git a/test/snapshot/batgrep/test_respects_bat_style.stdout.snapshot b/test/snapshot/batgrep/test_respects_bat_style.stdout.snapshot new file mode 100644 index 0000000..0463a83 --- /dev/null +++ b/test/snapshot/batgrep/test_respects_bat_style.stdout.snapshot @@ -0,0 +1,7 @@ +──────────────────────────────────────────────────────────────────────────────── +cat  +dog +car  +frog +fox +──────────────────────────────────────────────────────────────────────────────── diff --git a/test/suite/batgrep.sh b/test/suite/batgrep.sh index e5c5932..e1911a1 100644 --- a/test/suite/batgrep.sh +++ b/test/suite/batgrep.sh @@ -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 +}