From 2aecc91f94ba081e7ce0c5f5b48285faf9920442 Mon Sep 17 00:00:00 2001 From: Pablo Olmos de Aguilera Corradini Date: Wed, 8 Oct 2014 21:40:44 -0300 Subject: [PATCH] Modify http-server to work with python3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since python3, the SimpleHTTPServer has been merged as its stated in the [docs](https://docs.python.org/2/library/simplehttpserver.html): > The SimpleHTTPServer module has been merged into http.server in Python 3. The 2to3 tool will automatically adapt imports when converting your sources to Python 3. Most systems alias/redirect "python" to the latest python installed: ``` ❯❯❯ file /usr/bin/python /usr/bin/python: symbolic link to `python3' ``` They also kept a `python{2,3}`, depending on the major version even if only one is installed. So, in a system with only `python 2.x, with this change it should still work. (Another alternative would be run `python2 -m SimpleHTTPServer`. --- modules/utility/init.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/utility/init.zsh b/modules/utility/init.zsh index 5f7cffb9..3efd784e 100644 --- a/modules/utility/init.zsh +++ b/modules/utility/init.zsh @@ -145,7 +145,11 @@ fi # Miscellaneous # Serves a directory via HTTP. -alias http-serve='python -m SimpleHTTPServer' +if (($+commands[python3]); then + alias http-serve='python -m http.server' +elif (($+commands[python2]); then + alias http-serve='python -m SimpleHTTPServer' +fi # # Functions