From 3ea20cfbe8d55259016e37a69e4fae7356e322e0 Mon Sep 17 00:00:00 2001 From: Indrajit Raychaudhuri Date: Wed, 3 Aug 2022 15:37:00 -0500 Subject: [PATCH] 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. --- modules/utility/init.zsh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/utility/init.zsh b/modules/utility/init.zsh index c6dc3c0..c901591 100644 --- a/modules/utility/init.zsh +++ b/modules/utility/init.zsh @@ -196,12 +196,14 @@ fi # Serves a directory via HTTP. 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 + if (( $+commands[python3] )); then 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 - alias http-serve='$commands[(i)python(|2)] -m SimpleHTTPServer' + alias http-serve='python -m SimpleHTTPServer' fi fi