utils upgrade
This commit is contained in:
@@ -1,23 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
|
||||
port='8888'
|
||||
if [ $# -eq 1 ]; then
|
||||
port="$1"
|
||||
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
||||
cat <<EOF
|
||||
Usage: $(basename "$0") [-h] [port]
|
||||
|
||||
Start a simple HTTP server in current directory.
|
||||
|
||||
Options:
|
||||
-h, --help Show this help message
|
||||
|
||||
Arguments:
|
||||
port Port number (default: 8888)
|
||||
|
||||
EOF
|
||||
exit 0
|
||||
fi
|
||||
|
||||
port="${1:-8888}"
|
||||
|
||||
if hash php 2>/dev/null; then
|
||||
exec php -S "localhost:$port"
|
||||
exec php -S "localhost:$port"
|
||||
elif hash python3 2>/dev/null; then
|
||||
exec python3 -m http.server "$port"
|
||||
exec python3 -m http.server "$port"
|
||||
elif hash python 2>/dev/null; then
|
||||
major_version="$(python -c 'import platform as p;print(p.python_version_tuple()[0])')"
|
||||
if [[ "$major_version" == '3' ]]; then
|
||||
exec python -m http.server "$port"
|
||||
else
|
||||
exec python -m SimpleHTTPServer "$port"
|
||||
fi
|
||||
major_version="$(python -c 'import platform as p;print(p.python_version_tuple()[0])')"
|
||||
if [[ "$major_version" == '3' ]]; then
|
||||
exec python -m http.server "$port"
|
||||
else
|
||||
exec python -m SimpleHTTPServer "$port"
|
||||
fi
|
||||
else
|
||||
echo 'unable to start HTTP server' 1>&2
|
||||
exit 1
|
||||
echo 'unable to start HTTP server' 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user