Skip to content

Instantly share code, notes, and snippets.

@fish2000
Last active June 3, 2022 02:55
Show Gist options
  • Save fish2000/35ed4398f30e3d1de9a562fc82a655ee to your computer and use it in GitHub Desktop.
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
#!/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
@fish2000
Copy link
Author

Output looks like this:

PIPER-ALPHA:pygments-csv-lexer[master]$ brew receipt hdf5
{
    "homebrew_version": "1.7.7-122-gfdd8e9b",
    "used_options": [
        "--with-mpi"
    ],
    "unused_options": [

    ],
    "built_as_bottle": false,
    "poured_from_bottle": false,
    "installed_as_dependency": false,
    "installed_on_request": true,
    "changed_files": null,
    "time": 1540235045,
    "source_modified_time": 1538717168,
    "HEAD": "fdd8e9b7cf1e53322492e1e90f685c19bdfde506",
    "stdlib": "libcxx",
    "compiler": "clang",
    "aliases": [

    ],
    "runtime_dependencies": [
        {
            "full_name": "gmp",
            "version": "6.1.2"
        },
        {
            "full_name": "isl",
            "version": "0.20"
        },
        {
            "full_name": "mpfr",
            "version": "4.0.1"
        },
        {
            "full_name": "libmpc",
            "version": "1.1.0"
        },
        {
            "full_name": "gcc",
            "version": "8.2.0"
        },
        {
            "full_name": "szip",
            "version": "2.1.1"
        },
        {
            "full_name": "open-mpi",
            "version": "3.1.2"
        }
    ],
    "source": {
        "path": "/private/tmp/hdf5.rb",
        "tap": null,
        "spec": "stable",
        "versions": {
            "stable": "1.10.4",
            "devel": "",
            "head": "",
            "version_scheme": 0
        }
    }
}

Screen Shot 2019-03-11 at 6 27 52 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment