From 4f87376b507c712c0d401b43f1819604cb40833e Mon Sep 17 00:00:00 2001 From: Indrajit Raychaudhuri Date: Sat, 11 Feb 2017 16:39:48 -0600 Subject: [PATCH] Add support for 'pip', 'pip2', 'pip3' completion Since `pip completion --zsh` might be slow, we cache it beforehand. The implementation is along the lines of 'npm' completion in 'node' module. --- modules/python/init.zsh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/python/init.zsh b/modules/python/init.zsh index 458253b..8b63251 100644 --- a/modules/python/init.zsh +++ b/modules/python/init.zsh @@ -46,6 +46,20 @@ if (( $? && $+commands[virtualenvwrapper.sh] )); then source "$commands[virtualenvwrapper.sh]" fi +# Load PIP completion. +if (( $+commands[pip] )); then + cache_file="${0:h}/cache.zsh" + + if [[ "$commands[pip]" -nt "$cache_file" || ! -s "$cache_file" ]]; then + # pip is slow; cache its output. And also support 'pip2', 'pip3' variants + pip completion --zsh | sed -e "s|compctl -K [-_[:alnum:]]* pip|& pip2 pip3|" >! "$cache_file" 2> /dev/null + fi + + source "$cache_file" + + unset cache_file +fi + # # Aliases #