Skip to content
This repository has been archived by the owner on Nov 6, 2021. It is now read-only.
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
# 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"
}