Last active
February 4, 2020 16:17
-
-
Save tngranados/41e63c5bfb2eaa371750805b397d6dcb to your computer and use it in GitHub Desktop.
ZSH static server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Creates a static server using ruby, php, or python 2 or 3, whichever is | |
# available. It support an optional port (default is 8000). | |
shttp() { | |
local port="${1:-8000}" | |
if (( $+commands[ruby] )); then | |
ruby -run -ehttpd . -p$port | |
elif (( $+commands[php] )); then | |
php -S localhost:$port | |
elif (( $+commands[python] )); then | |
local pythonVer=$(python -c 'import platform; major, _, _ = platform.python_version_tuple(); print(major);') | |
if [ $pythonVer -eq 2 ]; then | |
python -m SimpleHTTPServer $port | |
else | |
python -m http.server $port | |
fi | |
else | |
echo "Error: Ruby, PHP or Python needed" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment