Skip to content

Instantly share code, notes, and snippets.

@rawnly
Created June 6, 2025 16:50
Show Gist options
  • Save rawnly/df5fdcec99399f2ffc99608122393bf7 to your computer and use it in GitHub Desktop.
Save rawnly/df5fdcec99399f2ffc99608122393bf7 to your computer and use it in GitHub Desktop.
#!/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