Last active
April 15, 2020 11:15
-
-
Save osmatsuda/a29a7826c90301c7f4697322c5e5da0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DOCROOT= | |
DEFAULT_PORT=8000 | |
SERVER="python -m http.server" | |
PORT= | |
if [[ $1 =~ ^[0-9]+$ ]] | |
then | |
PORT=$1 | |
elif [[ -z $1 ]] | |
then | |
PORT=$DEFAULT_PORT | |
else | |
echo "Usage: $0 [port]" | |
exit 0 | |
fi | |
TEST="$(nc -z localhost $PORT 2>&1 | grep succeeded)" | |
if [[ -n $TEST ]] | |
then | |
echo "Can't use address: localhost:$PORT" | |
exit 1 | |
fi | |
( | |
for i in 1 2 3 4 5; do | |
sleep 0.5 | |
TEST="$(nc -z localhost $PORT 2>&1 | grep succeeded)" | |
if [[ -n $TEST ]]; then | |
break | |
fi | |
done | |
if [[ -n $TEST ]]; then | |
open "http://localhost:$PORT/" | |
fi | |
) & | |
cd $DOCROOT | |
$SERVER $PORT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment