Created
February 25, 2026 04:36
-
-
Save samkcarlile/c462d0154b1f82f3c827d5e7bb9cb8d9 to your computer and use it in GitHub Desktop.
Syntax highlighting for every `--help` page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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