diff options
author | Mathias Bynens <mathias@qiwi.be> | 2011-12-28 20:09:49 +0100 |
---|---|---|
committer | Mathias Bynens <mathias@qiwi.be> | 2011-12-28 20:09:49 +0100 |
commit | 9b0af44766d2a2cc61ae0142ac3ec9f0bed75674 (patch) | |
tree | 6c9b88d0892d6e9d40345453bd0b5144e86271b2 /.functions | |
parent | 6b75bfc425a1db36f83bb7a180fb73694ac3e124 (diff) | |
download | dotfiles-9b0af44766d2a2cc61ae0142ac3ec9f0bed75674.tar.gz dotfiles-9b0af44766d2a2cc61ae0142ac3ec9f0bed75674.tar.bz2 dotfiles-9b0af44766d2a2cc61ae0142ac3ec9f0bed75674.zip |
Allow piping to the `json` function
Diffstat (limited to '.functions')
-rw-r--r-- | .functions | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -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 |