diff options
-rwxr-xr-x | bin/serve | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -5,7 +5,7 @@ set -eu usage() { cat <<-'EOF' Usage: - serve [-d DIRECTORY] [-p PORT] + serve [-d DIRECTORY] [-n] [-p PORT] serve -h EOF } @@ -16,6 +16,7 @@ help() { Options: -d DIRECTORY the directory to serve (default: ".") + -n do not open browser -p PORT the port to listen on (default: find one) -h, --help show this message @@ -55,7 +56,8 @@ done DIRECTORY='.' PORT="$(free-port)" -while getopts 'd:p:h' flag; do +OPEN_BROWSER=true +while getopts 'd:np:h' flag; do case "$flag" in (d) DIRECTORY="$OPTARG" @@ -63,6 +65,9 @@ while getopts 'd:p:h' flag; do (p) PORT="$OPTARG" ;; + (n) + OPEN_BROWSER=false + ;; (h) usage help @@ -75,6 +80,8 @@ while getopts 'd:p:h' flag; do esac done -open "http://localhost:$PORT" & +if [ "$OPEN_BROWSER" = true ]; then + open "http://localhost:$PORT" & +fi python3 -m http.server -d "$DIRECTORY" "$PORT" wait |