batdiff: Check delta version for --hunk-style

This adds compatibility for older `delta` versions.
This commit is contained in:
Ethan P. 2023-09-13 11:06:11 -07:00
parent 6f579b1d45
commit 4039859b62
No known key found for this signature in database
GPG Key ID: B29B90B1B228FEBC

View File

@ -34,6 +34,7 @@ SUPPORTS_DELTA=false
BAT_VERSION="$(bat_version)" BAT_VERSION="$(bat_version)"
BAT_ARGS=() BAT_ARGS=()
DELTA_ARGS=() DELTA_ARGS=()
DELTA_VERSION='unsupported'
GIT_ARGS=() GIT_ARGS=()
FILES=() FILES=()
@ -50,6 +51,15 @@ fi
# Set options based on delta availability. # Set options based on delta availability.
if command -v "$EXECUTABLE_DELTA" &>/dev/null; then if command -v "$EXECUTABLE_DELTA" &>/dev/null; then
SUPPORTS_DELTA=true 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 fi
# Parse arguments. # Parse arguments.
@ -83,7 +93,6 @@ BAT_ARGS+=("--terminal-width=${OPT_TERMINAL_WIDTH}" "--paging=never")
DELTA_ARGS+=( DELTA_ARGS+=(
"--width=${OPT_TERMINAL_WIDTH}" "--width=${OPT_TERMINAL_WIDTH}"
"--paging=never" "--paging=never"
"--hunk-header-decoration-style=plain"
) )
if "$OPT_COLOR"; then if "$OPT_COLOR"; then