Skip to content

Instantly share code, notes, and snippets.

@timofurrer
Created August 19, 2013 13:59
Show Gist options
  • Save timofurrer/6269456 to your computer and use it in GitHub Desktop.
Save timofurrer/6269456 to your computer and use it in GitHub Desktop.
open http server in current directory in bash
httpserver()
{
local port="${1:-8000}"
sleep 1 && 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"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment