From 4039859b62ddc81cce1c6717fc41235dcd9fffc6 Mon Sep 17 00:00:00 2001 From: "Ethan P." Date: Wed, 13 Sep 2023 11:06:11 -0700 Subject: [PATCH] batdiff: Check delta version for `--hunk-style` This adds compatibility for older `delta` versions. --- src/batdiff.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/batdiff.sh b/src/batdiff.sh index d4d3f70..8937011 100755 --- a/src/batdiff.sh +++ b/src/batdiff.sh @@ -34,6 +34,7 @@ SUPPORTS_DELTA=false BAT_VERSION="$(bat_version)" BAT_ARGS=() DELTA_ARGS=() +DELTA_VERSION='unsupported' GIT_ARGS=() FILES=() @@ -50,6 +51,15 @@ fi # Set options based on delta availability. if command -v "$EXECUTABLE_DELTA" &>/dev/null; then SUPPORTS_DELTA=true + DELTA_VERSION="$("$EXECUTABLE_DELTA" --version | cut -d' ' -f2)" +fi + +# Set options based on delta version. +# - 0.12 -- Renamed `--hunk-style` to `--hunk-header-decoration-style`. +if version_compare "$DELTA_VERSION" -ge "0.12"; then + DELTA_ARGS+=("--hunk-header-decoration-style=plain") +else + DELTA_ARGS+=("--hunk-style=plain") fi # Parse arguments. @@ -82,8 +92,7 @@ done BAT_ARGS+=("--terminal-width=${OPT_TERMINAL_WIDTH}" "--paging=never") DELTA_ARGS+=( "--width=${OPT_TERMINAL_WIDTH}" - "--paging=never" - "--hunk-header-decoration-style=plain" + "--paging=never" ) if "$OPT_COLOR"; then