From fae5e493ec8d323c5fc9256497d5ce35efbb44ba Mon Sep 17 00:00:00 2001 From: Indrajit Raychaudhuri Date: Sat, 8 May 2021 21:39:16 -0500 Subject: [PATCH] utility: Check best-fit Python version for 'http-serve' When creating `http-serve` alias, first check if Python is actually available. And, if available, apply the most specific version. --- modules/utility/init.zsh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/utility/init.zsh b/modules/utility/init.zsh index a06eff8..3757e40 100644 --- a/modules/utility/init.zsh +++ b/modules/utility/init.zsh @@ -184,10 +184,15 @@ fi # Miscellaneous # Serves a directory via HTTP. -if (( $+commands[python3] )); then - alias http-serve='python3 -m http.server' -else - alias http-serve='python -m SimpleHTTPServer' +if (( $#commands[(i)python(|[23])] )); then + autoload -Uz is-at-least + if is-at-least 3 ${"$(python --version 2>&1)"[(w)2]}; then + alias http-serve='python -m http.server' + elif (( $+commands[python3] )); then + alias http-serve='python3 -m http.server' + else + alias http-serve='$commands[(i)python(|2)] -m SimpleHTTPServer' + fi fi #