aboutsummaryrefslogtreecommitdiffstats
path: root/.functions
diff options
context:
space:
mode:
authorMathias Bynens <mathias@qiwi.be>2011-12-28 20:09:49 +0100
committerMathias Bynens <mathias@qiwi.be>2011-12-28 20:09:49 +0100
commit9b0af44766d2a2cc61ae0142ac3ec9f0bed75674 (patch)
tree6c9b88d0892d6e9d40345453bd0b5144e86271b2 /.functions
parent6b75bfc425a1db36f83bb7a180fb73694ac3e124 (diff)
downloaddotfiles-9b0af44766d2a2cc61ae0142ac3ec9f0bed75674.tar.gz
dotfiles-9b0af44766d2a2cc61ae0142ac3ec9f0bed75674.tar.bz2
dotfiles-9b0af44766d2a2cc61ae0142ac3ec9f0bed75674.zip
Allow piping to the `json` function
Diffstat (limited to '.functions')
-rw-r--r--.functions12
1 files changed, 10 insertions, 2 deletions
diff --git a/.functions b/.functions
index b5270b3..a6a576d 100644
--- a/.functions
+++ b/.functions
@@ -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