1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-12-22 13:58:00 +00:00

utility: Make 'http-serve' handler faster for well known cases

In most systems, python2 or python3 command/soft-link would almost
always exist. In such cases, we don't need to invoke `python` to
detect the version. This should speed things up a bit as well.
This commit is contained in:
Indrajit Raychaudhuri 2022-08-03 15:37:00 -05:00
parent 0aef8086b5
commit 3ea20cfbe8

View File

@ -196,12 +196,14 @@ fi
# Serves a directory via HTTP. # Serves a directory via HTTP.
if (( $#commands[(i)python(|[23])] )); then if (( $#commands[(i)python(|[23])] )); then
autoload -Uz is-at-least autoload -Uz is-at-least
if is-at-least 3 ${"$(python --version 2>&1)"[(w)2]}; then if (( $+commands[python3] )); then
alias http-serve='python -m http.server'
elif (( $+commands[python3] )); then
alias http-serve='python3 -m http.server' alias http-serve='python3 -m http.server'
elif (( $+commands[python2] )); then
alias http-serve='python2 -m SimpleHTTPServer'
elif is-at-least 3 ${"$(python --version 2>&1)"[(w)2]}; then
alias http-serve='python -m http.server'
else else
alias http-serve='$commands[(i)python(|2)] -m SimpleHTTPServer' alias http-serve='python -m SimpleHTTPServer'
fi fi
fi fi