summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Vink <ivi@vinkies.net>2025-10-23 21:04:03 +0200
committerMike Vink <ivi@vinkies.net>2025-10-23 21:04:03 +0200
commitfaa57cfdf051c56f8f3438536c85a6465b62041d (patch)
tree272e02cec11a9bdf4948716417b887001221e82e
parent4acdda4eff137071be4d7cb6293ecaf0cb2dd8d3 (diff)
serveit
-rwxr-xr-x.local/bin/serveit27
1 files changed, 27 insertions, 0 deletions
diff --git a/.local/bin/serveit b/.local/bin/serveit
new file mode 100755
index 0000000..fb3f17d
--- /dev/null
+++ b/.local/bin/serveit
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+set -e
+set -u
+set -o pipefail
+
+port='8000'
+if [ $# -eq 1 ]; then
+ port="$1"
+fi
+
+if hash php 2>/dev/null; then
+ exec php -S "localhost:$port"
+elif hash python3 2>/dev/null; then
+ 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
+elif hash ruby 2>/dev/null; then
+ exec ruby -run -e httpd . -p "$port"
+else
+ echo 'unable to start HTTP server' 1>&2
+ exit 1
+fi