Skip to content

Instantly share code, notes, and snippets.

@sterpe
Created October 29, 2015 23:28
Show Gist options
  • Save sterpe/e43a1d5549c96cdd1d97 to your computer and use it in GitHub Desktop.
Save sterpe/e43a1d5549c96cdd1d97 to your computer and use it in GitHub Desktop.
#!/bin/sh
# This is a utility command to clean up the various constants files.
#
# Usage is : ./scripts/constants.sh <file>
# It will alphabetize keys, and if any key is an array, it will
# alphabetize or order that array.
# It does not support multi-level nested objects but objects that
# look like this: { "key": "value" } or { "key": [] } only.
# The script requires that both `ed` and `jq` are on the $PATH.
ed -s $1 << EOF
H
\$-kx
\$r ! jq -S ' . | map_values( . as \$o | . = try sort catch \$o ) ' $1
1,'x+d
w
q
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment