diff --git a/sh/.config/sh/alias.d/batcat.sh b/sh/.config/sh/alias.d/batcat.sh new file mode 100644 index 0000000..36403e7 --- /dev/null +++ b/sh/.config/sh/alias.d/batcat.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env sh +# Make cat actually call bat if it exists. +# Give `rcat` as 'rawcat' replacement if needed. +# +# Mostly taken from https://github.com/fdellwing/zsh-bat +# sans MANPAGER +# +# shellcheck disable=SC2139 # (Expands when defined not used) +# We actively want it to check when defined so this is fine. + +# Save the original system `cat` under `rcat` +alias rcat="$(which cat)" +if command -v batcat >/dev/null 2>&1; then + # For Ubuntu and Debian-based `bat` packages + # the `bat` program is named `batcat` on these systems + alias cat="$(which batcat)" +elif command -v bat >/dev/null 2>&1; then + # For all other systems + alias cat="$(which bat)" +fi