From 1da451dff5abb8106773db78a2bba96ba4398dda Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Thu, 3 Aug 2023 11:12:35 +0200 Subject: [PATCH] Open the webserver URL in the default browser --- dev.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/dev.sh b/dev.sh index a41357d..4045f28 100755 --- a/dev.sh +++ b/dev.sh @@ -40,6 +40,22 @@ _setup () { overmind quit sleep 2 } + +_open_url () { + if [[ ! -z "${DEFAULT_BROWSER}" ]]; then + $DEFAULT_BROWSER $url + elif type explorer.exe &> /dev/null; then + explorer.exe $url + fi +} + +_create_url () { + if [ -f /etc/wsl.conf ]; then + echo "http://localhost:$WEBPORT" + else + echo "http://$(hostname -f):$WEBPORT" + fi +} #} # Main tasks start @@ -49,9 +65,11 @@ declare -A descriptions run () { _setup find . -name __pycache__ -o -name "*.pyc" -delete + url=$(_create_url) sudo iptables -I INPUT -p tcp --dport $WEBPORT -j ACCEPT - printf "\n---\n webserver: http://$(hostname -f):$WEBPORT\n---\n" overmind start -D + printf "\n---\n webserver: $url\n---\n" + _open_url $url } descriptions["run"]="Start the webserver." tasks["run"]=run