Skip to content

Instantly share code, notes, and snippets.

@samkcarlile
Created February 25, 2026 04:36
Show Gist options
  • Select an option

  • Save samkcarlile/c462d0154b1f82f3c827d5e7bb9cb8d9 to your computer and use it in GitHub Desktop.

Select an option

Save samkcarlile/c462d0154b1f82f3c827d5e7bb9cb8d9 to your computer and use it in GitHub Desktop.
Syntax highlighting for every `--help` page
help() {
if [[ -z "$1" ]]; then
echo "Usage: help <command>"
return 1
fi
local output
output=$("$@" --help 2>&1)
if [[ $? -ne 0 && -z "$output" ]]; then
echo "No help available for '$1'"
return 1
fi
# If the output contains ANSI color codes, display it directly
if echo "$output" | grep -q $'\['; then
echo "$output"
else
echo "$output" | bat -l help -p
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment