Skip to content

Instantly share code, notes, and snippets.

@cmawhorter
Created October 21, 2014 19:53
Show Gist options
  • Save cmawhorter/f2a09bcf63c68b0cff10 to your computer and use it in GitHub Desktop.
Save cmawhorter/f2a09bcf63c68b0cff10 to your computer and use it in GitHub Desktop.
Add alias to bash_profile to get a quick http server anywhere. Just type H to serve current directory.
# http://stackoverflow.com/a/12269225/670023
# Binds to localhost
alias H="echo 'Serving HTTP on 127.0.0.1 port 8000 ...'; python -c 'import BaseHTTPServer as bhs, SimpleHTTPServer as shs; bhs.HTTPServer((\"127.0.0.1\", 8000), shs.SimpleHTTPRequestHandler).serve_forever()'"
@lukasgraf
Copy link

Here's a version with an optional port argument (defaulting to 8000):

http () {
    PORT=${1:-8000}
    echo "Serving HTTP on 127.0.0.1 port ${PORT} ..."
    python -c "import BaseHTTPServer as bhs, SimpleHTTPServer as shs; bhs.HTTPServer(('127.0.0.1', ${PORT}), shs.SimpleHTTPRequestHandler).serve_forever()"
}
alias H=http

@cmawhorter
Copy link
Author

nice! i don't know why i didn't consider this sooner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment