From 4f55698f60700c58ae3e24dfa86af3cc059eab33 Mon Sep 17 00:00:00 2001 From: Bodaniel Jeanes Date: Wed, 22 Dec 2010 00:03:57 +1000 Subject: [PATCH] Add handy utility shell functions for fetching and formatting JSON/XML --- shell/aliases.sh | 2 ++ shell/functions.sh | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/shell/aliases.sh b/shell/aliases.sh index 3a76962..a0c66d7 100644 --- a/shell/aliases.sh +++ b/shell/aliases.sh @@ -35,3 +35,5 @@ alias webshare='python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"' alias pubkey="cat $HOME/.ssh/*.pub" alias colorslist="set | egrep 'COLOR_\w*'" # lists all the colors + +alias jsonify='python -mjson.tool' diff --git a/shell/functions.sh b/shell/functions.sh index 2afaf92..49c6ff2 100644 --- a/shell/functions.sh +++ b/shell/functions.sh @@ -66,3 +66,19 @@ function command_not_found_handle() { command_not_found_handler $* return $? } + +function json() { + tmpfile=`mktemp -t json` + curl -s $* | python -mjson.tool > $tmpfile + cat $tmpfile + cat $tmpfile | pbcopy + rm $tmpfile +} + +function xml() { + tmpfile=`mktemp -t xml` + curl -s $* | xmllint —format - > $tmpfile + cat $tmpfile + cat $tmpfile | pbcopy + rm $tmpfile +}