Skip to content

Instantly share code, notes, and snippets.

@DanGe42
Last active December 16, 2015 07:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DanGe42/5400408 to your computer and use it in GitHub Desktop.
Save DanGe42/5400408 to your computer and use it in GitHub Desktop.
Python "one-liner" to start a server to serve static files from a directory
# Start an HTTP server from a directory, optionally specifying the port
function server() {
# Default to port 8000
local port="${1:-8000}"
# Since the one-liner blocks, we open the browser beforehand. However, we want to
# wait just a couple of seconds since the server will not be ready just yet.
# Also, I think Linux users should be able to use 'xdg-open' ('open' is for OS X).
( sleep 2; open "http://localhost:${port}/" ) &
python -m SimpleHTTPServer "$port"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment