Last active
June 3, 2022 02:55
-
-
Save fish2000/35ed4398f30e3d1de9a562fc82a655ee to your computer and use it in GitHub Desktop.
Homebrew external-command script to show syntax-highlited install receipt JSON, using Pygments
This file contains 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 | |
#: * `receipt` <formula> [<formula>...]: | |
#: Show the syntax-highlighted JSON install receipt for the specified formulae | |
function brew () { | |
"${HOMEBREW_PREFIX}/bin/brew" "$@" | |
} | |
irfilename="INSTALL_RECEIPT.json" | |
pygmentize="$(command -v pygmentize)" | |
json_refmt="$(command -v json_reformat)" | |
if [[ ! -x $pygmentize ]]; then | |
echo "* ERROR: The “pygmentize” command was not found" | |
echo "* ERROR: Try installing the Python “pygments” package" | |
return 1 | |
fi | |
if [[ ! -x $json_refmt ]]; then | |
echo "* ERROR: The “json_reformat” command was not found" | |
echo "* ERROR: Try installing the “yajl” Homebrew formula" | |
return 1 | |
fi | |
for argument in "$@"; do | |
if brew ls --versions $argument > /dev/null; then | |
basedir="$(brew --prefix ${argument})" | |
receipt="${basedir}/${irfilename}" | |
if [[ ! -r $receipt ]]; then | |
echo "* ERROR: can’t read install receipt for formula: ${argument}" | |
echo "* ERROR: ${receipt}" | |
return 1 | |
else | |
"${json_refmt}" < "${receipt}" | "${pygmentize}" -l json -O "style=paraiso-dark" | |
echo "" | |
fi | |
else | |
echo "* ERROR: Formula ${argument} not installed" | |
echo "" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output looks like this: