Skip to content

Commit

Permalink
simply serve directory
Browse files Browse the repository at this point in the history
  • Loading branch information
eriwen committed Apr 6, 2012
1 parent 13874f2 commit 27ed331
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion .functions
Expand Up @@ -23,4 +23,13 @@ function quit() {
# Better man
function man() {
/usr/bin/man $@ || (help $@ 2> /dev/null && help $@ | less)
}
}

# 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"
}

0 comments on commit 27ed331

Please sign in to comment.