Add handy utility shell functions for fetching and formatting JSON/XML

pull/2/head
Bodaniel Jeanes 2010-12-22 00:03:57 +10:00
parent b03eb1ee1e
commit 4f55698f60
2 changed files with 18 additions and 0 deletions

View File

@ -35,3 +35,5 @@ alias webshare='python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"'
alias pubkey="cat $HOME/.ssh/*.pub" alias pubkey="cat $HOME/.ssh/*.pub"
alias colorslist="set | egrep 'COLOR_\w*'" # lists all the colors alias colorslist="set | egrep 'COLOR_\w*'" # lists all the colors
alias jsonify='python -mjson.tool'

View File

@ -66,3 +66,19 @@ function command_not_found_handle() {
command_not_found_handler $* command_not_found_handler $*
return $? 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
}