Skip to content

Instantly share code, notes, and snippets.

@creativeaura
Forked from DanGe42/server.sh
Created May 9, 2013 10:30
Show Gist options
  • Save creativeaura/5546765 to your computer and use it in GitHub Desktop.
Save creativeaura/5546765 to your computer and use it in GitHub Desktop.
# 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