From 528a4e7fce7ed208b884c7778acc94955aee46b3 Mon Sep 17 00:00:00 2001
From: Marty Oehme <marty.oehme@gmail.com>
Date: Sun, 23 Feb 2025 22:15:18 +0100
Subject: [PATCH] sh: Add bat to cat alias

Always call `bat` when we invoke `cat`. There is not ever a time when I
want to use the bog standard `cat` in preference to `bat`.

However, on the very slight off-chance there is, we still have a
fallback alias on `rcat` which invokes 'raw' cat instead.
---
 sh/.config/sh/alias.d/batcat.sh | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 sh/.config/sh/alias.d/batcat.sh

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