aboutsummaryrefslogtreecommitdiff
path: root/bin/serve
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-09-11 17:42:58 -0300
committerEuAndreh <eu@euandre.org>2024-09-11 17:42:58 -0300
commit620b5f9d57d1e8d7392c81194b255c83ec2d9db1 (patch)
treefd05b2f47a6456c0312145bb972b292633f350ae /bin/serve
parentrm bin/untill: Moved to eut (diff)
downloaddotfiles-620b5f9d57d1e8d7392c81194b255c83ec2d9db1.tar.gz
dotfiles-620b5f9d57d1e8d7392c81194b255c83ec2d9db1.tar.xz
bin/serve: Add -n option
Diffstat (limited to 'bin/serve')
-rwxr-xr-xbin/serve13
1 files changed, 10 insertions, 3 deletions
diff --git a/bin/serve b/bin/serve
index efece93..dff4414 100755
--- a/bin/serve
+++ b/bin/serve
@@ -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