Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
17 lines (15 sloc) 787 Bytes
# Start an HTTP server from a directory, optionally specifying the port
function pyserver() {
# Get port (if specified)
local port="${1:-8000}"
# Open in the browser
open "http://localhost:${port}/"
# Redefining the default content-type to text/plain instead of the default
# application/octet-stream allows "unknown" files to be viewable in-browser
# as text instead of being downloaded.
# Unfortunately, "python -m SimpleHTTPServer" doesn't allow you to redefine
# the default content-type, but the SimpleHTTPServer module can be executed
# manually with just a few lines of code.
python -c $'import SimpleHTTPServer;\nSimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map[""] = "text/plain";\nSimpleHTTPServer.test();' "$port"