Skip to content

Commit

Permalink
Allow piping to the json function
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbynens committed Dec 28, 2011
1 parent 6b75bfc commit 9b0af44
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions .functions
Expand Up @@ -9,9 +9,17 @@ function httpcompression() {
encoding="$(curl -LIs -H 'User-Agent: Mozilla/5 Gecko' -H 'Accept-Encoding: gzip,deflate,compress,sdch' "$1" | grep '^Content-Encoding:')" && echo "$1 is encoded using ${encoding#* }" || echo "$1 is not using any encoding"
}

# Syntax-highlight JSON files
# Syntax-highlight JSON strings or files
function json() {
python -mjson.tool <<< "$*" | pygmentize -l javascript
if [ -p /dev/stdin ]; then
# piping, e.g. `echo '{"foo":42}' | json`
while read data; do
python -mjson.tool <<< "$data" | pygmentize -l javascript
done
else
# e.g. `json '{"foo":42}'`
python -mjson.tool <<< "$*" | pygmentize -l javascript
fi
}

# All the dig info
Expand Down

0 comments on commit 9b0af44

Please sign in to comment.