aboutsummaryrefslogtreecommitdiffstats
path: root/.functions
diff options
context:
space:
mode:
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