Skip to content

Instantly share code, notes, and snippets.

@mythosil
Created October 9, 2013 15:35
Show Gist options
  • Save mythosil/6903175 to your computer and use it in GitHub Desktop.
Save mythosil/6903175 to your computer and use it in GitHub Desktop.
start simple http server serve static files in the current directory
#!/bin/sh
function http_server() {
local PORT=8888
if [ $# -ne 0 ]; then
expr $1 + 1 > /dev/null 2>&1
if [ $? -lt 2 ]; then
PORT=$1
else
echo "Usage: http_server <port>" return 1
fi
fi
local PYVER=`python -V 2>&1 > /dev/null | cut -d' ' -f2`
if expr $PYVER : "2" > /dev/null; then
python -m SimpleHTTPServer $PORT
elif expr $PYVER : "3" > /dev/null; then
python -m http.server $PORT
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment