Created
June 6, 2025 16:50
-
-
Save rawnly/df5fdcec99399f2ffc99608122393bf7 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
## Usage | |
# better_cat <file> | |
# better_cat package.json -r '[.name, .version] | join("@")' | |
# better_cat README.md | |
if [ -z "$1" ]; then | |
echo "Usage: better_cat <file>" | |
exit 1 | |
fi | |
file="$1" | |
filename=$(basename "$file") | |
extension="${filename##*.}" | |
if [ -z "$filename" ]; then | |
echo "Invalid file name: $filename" | |
exit 1 | |
fi | |
shift | |
if [[ $extension = "md" ]]; then | |
glow <"$file" | |
elif [[ $extension = "json" ]]; then | |
# Check if there are any arguments | |
if [ $# -eq 0 ]; then | |
# No arguments, just display the JSON | |
jq '.' "$file" | |
else | |
# Pass the remaining arguments to jq | |
jq "$@" "$file" | |
fi | |
else | |
bat --theme=1337 --style=header,grid,snip,changes "$file" "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment