Skip to content

Instantly share code, notes, and snippets.

@cboddy
Last active June 17, 2018 10:14
Show Gist options
  • Save cboddy/d5c38348a2ae07bcf8f1348b6a54813d to your computer and use it in GitHub Desktop.
Save cboddy/d5c38348a2ae07bcf8f1348b6a54813d to your computer and use it in GitHub Desktop.
A bash function to pretty print a file or cbor-encoded data.
#!/bin/bash
#
# add to ~/.bashrc or similar
#
# usage:
#
# > cbor_print /path/to/my/file.cbor
function cbor_print() {
# pretty print the contents of a file of cbor-encoded data
if python -c 'import cbor'; then
python -c "import cbor; from pprint import pprint; pprint((cbor.load(open('$1'))))";
else
echo "Error: requires the python cbor package eg."
echo " pip install cbor"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment