Permalink
Browse files

added some functions (server, gurl, json)

  • Loading branch information...
Aqua-Ye committed May 1, 2012
1 parent e02e217 commit 4efd72691aa383014f2d8a40d20b11493edaaa63
Showing with 25 additions and 0 deletions.
  1. +25 −0 .source/functions
View
@@ -135,6 +135,31 @@ function title() {
echo -e "\033];$1\007"
}
+# Start an HTTP server from a directory, optionally specifying the port
+function server() {
+ local port="${1:-8000}"
+ open "http://localhost:${port}/"
+ # Set the default Content-Type to `text/plain` instead of `application/octet-stream`
+ # And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
+ python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"
+}
+
+# Gzip-enabled `curl`
+function gurl() {
+ curl -sH "Accept-Encoding: gzip" "$@" | gunzip
+}
+
+# Syntax-highlight JSON strings or files
+function json() {
+ if [ -p /dev/stdin ]; then
+ # piping, e.g. `echo '{"foo":42}' | json`
+ python -mjson.tool | pygmentize -l javascript
+ else
+ # e.g. `json '{"foo":42}'`
+ python -mjson.tool <<< "$*" | pygmentize -l javascript
+ fi
+}
+
# Usage : seq n m [i]
# echo all integers between n and m using a skip or increment of i
# function seq ()

0 comments on commit 4efd726

Please sign in to comment.