3 ms·
I use python for serving my local static site development with this custom little bash wrapper script I wrote: #!/usr/bin/env bash set -e; [[ $TRACE ]]
by nodesocket 1y ago
I use python for serving my local static site development with this custom little bash wrapper script I wrote:
#!/usr/bin/env bash
set -e; [[ $TRACE ]] && set -x
port=8080
dir="."
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "usage: http-server [PORT] [DIRECTORY]"
echo " PORT Port to listen on (default: 8080)"
echo " DIRECTORY Directory to serve (default: .)"
exit 0
fi
if [ -n "$1" ]; then
port=$1
fi
if [[ -n "$2" ]]; then
dir=$2
fi
python3 -m http.server --directory "$dir" --protocol HTTP/1.1 "$port"
- Y_Y 1y agoFrom the people who brought you Useless Use of Cat, here's our newest innovation: Useless Use of Bash! That whole script could just be the last line! Maybe you could add defaults like "${port:-8080}"
- nodesocket 1y agoFair, but don't need to be snooty about it. :-) port="${1:-8080}" dir="${2:-.}"
- DiggyJohnson 1y agoGenuinely curious about what the full script would look like in consideration of your feedback.
- porridgeraisin 1y agopython3 -m http.server "${$1:-8080}" "${$2:-.}"
- Y_Y 1y agoAlmost! That will read the variable whose name is is the script argument. Also the directory argument needs a flag on my setup. It should be: python3 -mhttp.server "${1:-8080}" -d "${2:-.}"
- porridgeraisin 1y agoYep, you're right.