mirror of
https://github.com/conda-incubator/conda-zsh-completion.git
synced 2026-10-20 04:25:20 +08:00
implement caching of packages for 12 hours
This commit is contained in:
@@ -16,6 +16,14 @@
|
||||
# $ fpath+=$PWD/conda-zsh-completion
|
||||
# $ compinit conda-zsh-completion
|
||||
#
|
||||
# To activate the completion cache for packages, add the following to your
|
||||
# .zshrc:
|
||||
#
|
||||
# zstyle ':completion::complete:*' use-cache 1
|
||||
#
|
||||
# To forcefully clean the completion cache, look in '~/.zcompcache' and remove
|
||||
# file starting with 'conda_'.
|
||||
#
|
||||
# TODO
|
||||
# ----
|
||||
#
|
||||
@@ -24,8 +32,8 @@
|
||||
# * 'conda config --get' only completes a single option.
|
||||
# * 'conda config --add' completes only the key, not the value.
|
||||
# * Similar issues for other options.
|
||||
# * Completion for 'conda install' and others that query list of available or
|
||||
# existing packages is slow, consider caching.
|
||||
# * Example of activating cache only for conda completion
|
||||
# * Make cache policy configurable
|
||||
# * Completion for version numbers is entirely missing:
|
||||
# e.g. 'conda install numpy==<TAB>' should complete all available versions of
|
||||
# numpy.
|
||||
@@ -46,21 +54,29 @@ __conda_envs(){
|
||||
}
|
||||
|
||||
__conda_packages_installed(){
|
||||
local -a packages
|
||||
packages=($(conda list | sed 1,2d | cut -f1 -d' '))
|
||||
_describe -t packages 'installed packages' packages
|
||||
zstyle ":completion:${curcontext}:" cache-policy _conda_caching_policy
|
||||
local -a installed_packages
|
||||
if _cache_invalid conda_installed_packages || ! _retrieve_cache conda_installed_packages ; then
|
||||
installed_packages=($(conda list | sed 1,2d | cut -f1 -d' '))
|
||||
_store_cache conda_installed_packages installed_packages
|
||||
fi
|
||||
_describe -t installed_packages 'installed packages' installed_packages
|
||||
}
|
||||
|
||||
__conda_packages_search(){
|
||||
local -a packages
|
||||
packages=($(conda search --use-index-cache --json |
|
||||
python -c "
|
||||
zstyle ":completion:${curcontext}:" cache-policy _conda_caching_policy
|
||||
local -a available_packages
|
||||
if _cache_invalid conda_available_packages || ! _retrieve_cache conda_available_packages ; then
|
||||
available_packages=($(conda search --use-index-cache --json |
|
||||
python -c "
|
||||
import json, sys
|
||||
parsed = json.load(sys.stdin)
|
||||
for k in parsed.keys():
|
||||
print(k)
|
||||
"))
|
||||
_describe -t packages 'available packages' packages
|
||||
_store_cache conda_available_packages available_packages
|
||||
fi
|
||||
_describe -t available_packages 'available packages' available_packages
|
||||
}
|
||||
|
||||
__conda_channels(){
|
||||
@@ -128,6 +144,12 @@ __conda_commands(){
|
||||
_describe -t special_commands "special commands" special
|
||||
}
|
||||
|
||||
_conda_caching_policy() {
|
||||
local -a oldp
|
||||
oldp=( "$1"(Nmh+12) ) # 12 hour
|
||||
(( $#oldp ))
|
||||
}
|
||||
|
||||
local -a opts
|
||||
opts=(
|
||||
'(-h --help)'{-h,--help}'[show this help message and exit]'
|
||||
|
||||
Reference in New Issue
Block a user