From 6baabbd4af071ba7426cc242d302163028f46a67 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Fri, 13 Feb 2015 15:25:41 +0100 Subject: [PATCH 01/17] complete values for add, set and remove --- _conda | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_conda b/_conda index cf88dc7..c7d60ff 100644 --- a/_conda +++ b/_conda @@ -311,9 +311,9 @@ case $state in '--system[write to the system .condarc file]' \ '--file[write to the given file.]:file:_path_files' \ '--get[get the configuration value]:key:__conda_config' \ - '--add[add one configuration value to a list key]:key:__conda_config' \ - '--set[set a boolean key]:key:__conda_config' \ - '--remove[remove a configuration value from a list key]:key:__conda_config' \ + '--add[add one configuration value to a list key]:key:__conda_config:value:' \ + '--set[set a boolean key]:key:__conda_config:value:' \ + '--remove[remove a configuration value from a list key]:key:__conda_config:value' \ '--remove-key[remove a configuration key (and all its values)]:key:__conda_config' \ '(-f --force)'{-f,--force}'[write to the config file using the yaml parser]' \ ;; From 0d72ed7e1d211115dbf9ffc35b8996400f695dc2 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Fri, 13 Feb 2015 15:31:33 +0100 Subject: [PATCH 02/17] generalize reading config --- _conda | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/_conda b/_conda index c7d60ff..5203aae 100644 --- a/_conda +++ b/_conda @@ -97,15 +97,22 @@ for k in parsed.keys(): _describe -t available_packages 'available packages' available_packages } -__conda_channels(){ - local -a channels - channels=($(conda config --json --get channels| +__conda_config_values(){ + local -a config_values search_term + search_term="$1" + config_values=($(conda config --json --get "$search_term"| python -c " import json, sys -channels = json.load(sys.stdin)['get']['channels'] -for c in channels: - print(c) +values = json.load(sys.stdin)['get']['$search_term'] +for v in values: + print(v) ")) + print $config_values +} + +__conda_channels(){ + local -a channels + channels=$( __conda_config_values "channels" ) channels+=(system) _describe -t channels 'conda channels' channels } From d2e45484bd06dadcd14b1cff436bc7573e8dea6b Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Fri, 13 Feb 2015 15:43:26 +0100 Subject: [PATCH 03/17] config manipulators are now mutually exclusive --- _conda | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/_conda b/_conda index 5203aae..fb79386 100644 --- a/_conda +++ b/_conda @@ -317,11 +317,11 @@ case $state in $json_opts \ '--system[write to the system .condarc file]' \ '--file[write to the given file.]:file:_path_files' \ - '--get[get the configuration value]:key:__conda_config' \ - '--add[add one configuration value to a list key]:key:__conda_config:value:' \ - '--set[set a boolean key]:key:__conda_config:value:' \ - '--remove[remove a configuration value from a list key]:key:__conda_config:value' \ - '--remove-key[remove a configuration key (and all its values)]:key:__conda_config' \ + '( --add --set --remove --remove-key)--get[get the configuration value]:key:__conda_config' \ + '(--get --set --remove --remove-key)--add[add one configuration value to a list key]:key:__conda_config:value:' \ + '(--get --add --remove --remove-key)--set[set a boolean key]:key:__conda_config:value:' \ + '(--get --add --set --remove-key)--remove[remove a configuration value from a list key]:key:__conda_config:value' \ + '(--get --add --set --remove )--remove-key[remove a configuration key (and all its values)]:key:__conda_config' \ '(-f --force)'{-f,--force}'[write to the config file using the yaml parser]' \ ;; (init) From cf606c9cd9f3d59e55b05003ad74d11e1d008057 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Fri, 13 Feb 2015 18:41:46 +0100 Subject: [PATCH 04/17] more advanced completion for config --get --- _conda | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/_conda b/_conda index fb79386..409dd64 100644 --- a/_conda +++ b/_conda @@ -117,25 +117,25 @@ __conda_channels(){ _describe -t channels 'conda channels' channels } +config_options=('channels' + 'disallow' + 'create_default_packages' + 'track_features' + 'envs_dirs' + 'add_binstar_token' + 'always_yes' + 'allow_softlinks' + 'changeps1' + 'use_pip' + 'offline' + 'binstar_upload' + 'binstar_personal' + 'show_channel_urls' + 'allow_other_channels' + 'ssl_verify' + ) + __conda_config(){ - local config_options - config_options=('channels' - 'disallow' - 'create_default_packages' - 'track_features' - 'envs_dirs' - 'add_binstar_token' - 'always_yes' - 'allow_softlinks' - 'changeps1' - 'use_pip' - 'offline' - 'binstar_upload' - 'binstar_personal' - 'show_channel_urls' - 'allow_other_channels' - 'ssl_verify' - ) _describe -t config_options 'conda configuration' config_options } @@ -313,6 +313,13 @@ case $state in '*:packages:__conda_packages_installed' \ ;; (config) + # this allows completing multiple keys + last_item=$line[$CURRENT-1] + if [[ ${line[(r)--get]} == --get ]] && [[ ${config_options[(r)$last_item]} == $last_item ]] ; then + get_opts=('*:keys:__conda_config') + else + get_opts='' + fi _arguments -C $help_opts \ $json_opts \ '--system[write to the system .condarc file]' \ @@ -323,6 +330,7 @@ case $state in '(--get --add --set --remove-key)--remove[remove a configuration value from a list key]:key:__conda_config:value' \ '(--get --add --set --remove )--remove-key[remove a configuration key (and all its values)]:key:__conda_config' \ '(-f --force)'{-f,--force}'[write to the config file using the yaml parser]' \ + $get_opts ;; (init) _arguments -C $help_opts \ From 19dd8922f3c9e60c7de034d12aaade9dcf115c3d Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Fri, 13 Feb 2015 22:26:17 +0100 Subject: [PATCH 05/17] offer to remove only those values that are defined --- _conda | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/_conda b/_conda index 409dd64..032b2a4 100644 --- a/_conda +++ b/_conda @@ -107,7 +107,13 @@ values = json.load(sys.stdin)['get']['$search_term'] for v in values: print(v) ")) - print $config_values + print -l $config_values +} + +__conda_config_values_describe(){ + local -a config_values + config_values=($( __conda_config_values $1 )) + _describe -t config_values 'configuration values' config_values } __conda_channels(){ @@ -327,7 +333,7 @@ case $state in '( --add --set --remove --remove-key)--get[get the configuration value]:key:__conda_config' \ '(--get --set --remove --remove-key)--add[add one configuration value to a list key]:key:__conda_config:value:' \ '(--get --add --remove --remove-key)--set[set a boolean key]:key:__conda_config:value:' \ - '(--get --add --set --remove-key)--remove[remove a configuration value from a list key]:key:__conda_config:value' \ + '(--get --add --set --remove-key)--remove[remove a configuration value from a list key]:key:__conda_config:value:{__conda_config_values_describe '$last_item'}' \ '(--get --add --set --remove )--remove-key[remove a configuration key (and all its values)]:key:__conda_config' \ '(-f --force)'{-f,--force}'[write to the config file using the yaml parser]' \ $get_opts From 8756657d231c1a12641456a64e16bf169b2e2faa Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Fri, 13 Feb 2015 22:35:30 +0100 Subject: [PATCH 06/17] improved error handling for --remove --- _conda | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/_conda b/_conda index 032b2a4..5d57b2c 100644 --- a/_conda +++ b/_conda @@ -103,17 +103,25 @@ __conda_config_values(){ config_values=($(conda config --json --get "$search_term"| python -c " import json, sys -values = json.load(sys.stdin)['get']['$search_term'] -for v in values: - print(v) +try: + values = json.load(sys.stdin)['get']['$search_term'] + for v in values: + print(v) +except KeyError: + pass ")) print -l $config_values } __conda_config_values_describe(){ - local -a config_values - config_values=($( __conda_config_values $1 )) - _describe -t config_values 'configuration values' config_values + local -a config_values search_term + search_term="$1" + config_values=($( __conda_config_values $search_term )) + if [ "${#config_values}" == 0 ] ; then + _message "no values found for '$search_term'!" + else + _describe -t config_values 'configuration values' config_values + fi } __conda_channels(){ From 7c63b94ce2983ed890eaccfd82e36f464322bc5d Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Sat, 14 Feb 2015 17:21:14 +0100 Subject: [PATCH 07/17] refactor boolean and list keys --- _conda | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/_conda b/_conda index 5d57b2c..6392550 100644 --- a/_conda +++ b/_conda @@ -131,28 +131,43 @@ __conda_channels(){ _describe -t channels 'conda channels' channels } -config_options=('channels' - 'disallow' - 'create_default_packages' - 'track_features' - 'envs_dirs' - 'add_binstar_token' - 'always_yes' - 'allow_softlinks' - 'changeps1' - 'use_pip' - 'offline' - 'binstar_upload' - 'binstar_personal' - 'show_channel_urls' - 'allow_other_channels' - 'ssl_verify' - ) +boolean_config_options=( + 'add_binstar_token' + 'always_yes' + 'allow_softlinks' + 'changeps1' + 'use_pip' + 'offline' + 'binstar_upload' + 'binstar_personal' + 'show_channel_urls' + 'allow_other_channels' + 'ssl_verify' + ) + +list_config_options=( + 'channels' + 'disallow' + 'create_default_packages' + 'track_features' + 'envs_dirs' + ) + +__boolean_conda_config(){ + _describe -t boolean_config_options 'boolean keys' boolean_config_options +} + +__list_conda_config(){ + _describe -t list_config_options 'list keys' list_config_options +} + +config_options=($boolean_config_options $list_config_options) __conda_config(){ - _describe -t config_options 'conda configuration' config_options + _describe -t config_options 'conda configuration keys' config_options } + __conda_commands(){ local -a package maint environment help config special package=( @@ -339,8 +354,8 @@ case $state in '--system[write to the system .condarc file]' \ '--file[write to the given file.]:file:_path_files' \ '( --add --set --remove --remove-key)--get[get the configuration value]:key:__conda_config' \ - '(--get --set --remove --remove-key)--add[add one configuration value to a list key]:key:__conda_config:value:' \ - '(--get --add --remove --remove-key)--set[set a boolean key]:key:__conda_config:value:' \ + '(--get --set --remove --remove-key)--add[add one configuration value to a list key]:key:__list_conda_config:value:' \ + '(--get --add --remove --remove-key)--set[set a boolean key]:key:__boolean_conda_config:value:' \ '(--get --add --set --remove-key)--remove[remove a configuration value from a list key]:key:__conda_config:value:{__conda_config_values_describe '$last_item'}' \ '(--get --add --set --remove )--remove-key[remove a configuration key (and all its values)]:key:__conda_config' \ '(-f --force)'{-f,--force}'[write to the config file using the yaml parser]' \ From 342df8ff00e3c1e09a500141020d36a248ca24d4 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Sat, 14 Feb 2015 17:21:20 +0100 Subject: [PATCH 08/17] localize some variables --- _conda | 1 + 1 file changed, 1 insertion(+) diff --git a/_conda b/_conda index 6392550..21811fb 100644 --- a/_conda +++ b/_conda @@ -343,6 +343,7 @@ case $state in ;; (config) # this allows completing multiple keys + local -a last_item get_opts last_item=$line[$CURRENT-1] if [[ ${line[(r)--get]} == --get ]] && [[ ${config_options[(r)$last_item]} == $last_item ]] ; then get_opts=('*:keys:__conda_config') From fea60aa84a6c1abf932c1aba693c45463fa1efc6 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Sat, 14 Feb 2015 17:24:52 +0100 Subject: [PATCH 09/17] autocomplete boolean config values --- _conda | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/_conda b/_conda index 21811fb..716affd 100644 --- a/_conda +++ b/_conda @@ -124,6 +124,13 @@ __conda_config_values_describe(){ fi } +__conda_boolean_config_value(){ + local -a config_values + config_values=(True False) + _describe -t config_values 'boolean configuration values' config_values + +} + __conda_channels(){ local -a channels channels=$( __conda_config_values "channels" ) @@ -356,7 +363,7 @@ case $state in '--file[write to the given file.]:file:_path_files' \ '( --add --set --remove --remove-key)--get[get the configuration value]:key:__conda_config' \ '(--get --set --remove --remove-key)--add[add one configuration value to a list key]:key:__list_conda_config:value:' \ - '(--get --add --remove --remove-key)--set[set a boolean key]:key:__boolean_conda_config:value:' \ + '(--get --add --remove --remove-key)--set[set a boolean key]:key:__boolean_conda_config:value:__conda_boolean_config_value' \ '(--get --add --set --remove-key)--remove[remove a configuration value from a list key]:key:__conda_config:value:{__conda_config_values_describe '$last_item'}' \ '(--get --add --set --remove )--remove-key[remove a configuration key (and all its values)]:key:__conda_config' \ '(-f --force)'{-f,--force}'[write to the config file using the yaml parser]' \ From dc1400f1ae6733dbd12a1273fa82daa28f8f75ba Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Sat, 14 Feb 2015 17:28:04 +0100 Subject: [PATCH 10/17] be mor specific which keys we are dealing with --- _conda | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_conda b/_conda index 716affd..9988934 100644 --- a/_conda +++ b/_conda @@ -362,9 +362,9 @@ case $state in '--system[write to the system .condarc file]' \ '--file[write to the given file.]:file:_path_files' \ '( --add --set --remove --remove-key)--get[get the configuration value]:key:__conda_config' \ - '(--get --set --remove --remove-key)--add[add one configuration value to a list key]:key:__list_conda_config:value:' \ - '(--get --add --remove --remove-key)--set[set a boolean key]:key:__boolean_conda_config:value:__conda_boolean_config_value' \ - '(--get --add --set --remove-key)--remove[remove a configuration value from a list key]:key:__conda_config:value:{__conda_config_values_describe '$last_item'}' \ + '(--get --set --remove --remove-key)--add[add one configuration value to a list key]:list key:__list_conda_config:value:' \ + '(--get --add --remove --remove-key)--set[set a boolean key]:boolean key:__boolean_conda_config:value:__conda_boolean_config_value' \ + '(--get --add --set --remove-key)--remove[remove a configuration value from a list key]:list key:__list_conda_config:value:{__conda_config_values_describe '$last_item'}' \ '(--get --add --set --remove )--remove-key[remove a configuration key (and all its values)]:key:__conda_config' \ '(-f --force)'{-f,--force}'[write to the config file using the yaml parser]' \ $get_opts From 7470c197954da7af3c3842dcf96a8ea82883d6cb Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Sat, 14 Feb 2015 17:30:37 +0100 Subject: [PATCH 11/17] update comment --- _conda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_conda b/_conda index 9988934..a03bf03 100644 --- a/_conda +++ b/_conda @@ -349,7 +349,7 @@ case $state in '*:packages:__conda_packages_installed' \ ;; (config) - # this allows completing multiple keys + # this allows completing multiple keys whet --get is given local -a last_item get_opts last_item=$line[$CURRENT-1] if [[ ${line[(r)--get]} == --get ]] && [[ ${config_options[(r)$last_item]} == $last_item ]] ; then From 0bdf369c8a0cfd7aab604668341393cf95829274 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Sat, 14 Feb 2015 18:20:07 +0100 Subject: [PATCH 12/17] fixup syntax --- _conda | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_conda b/_conda index a03bf03..fbb4acb 100644 --- a/_conda +++ b/_conda @@ -10,14 +10,14 @@ # This completion depends on Python for a json parser, sorry. Unfortunately # there is no such thing in zsh (yet). # -# To use this completion drop it somewhere in you $fpath, e.g.: +# To use this completion drop it somewhere in you '$fpath', e.g.: # # $ git clone $CLONEURL # $ fpath+=$PWD/conda-zsh-completion # $ compinit conda # # To activate the completion cache for packages, add the following to your -# .zshrc: +# '.zshrc': # # zstyle ':completion::complete:*' use-cache 1 # From 81dc5b863acf28785eef26879538e6bc35d83844 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Sat, 14 Feb 2015 18:31:44 +0100 Subject: [PATCH 13/17] refactor for a little more sanity --- _conda | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/_conda b/_conda index fbb4acb..29e27be 100644 --- a/_conda +++ b/_conda @@ -97,7 +97,7 @@ for k in parsed.keys(): _describe -t available_packages 'available packages' available_packages } -__conda_config_values(){ +__conda_existing_config_values(){ local -a config_values search_term search_term="$1" config_values=($(conda config --json --get "$search_term"| @@ -113,10 +113,10 @@ except KeyError: print -l $config_values } -__conda_config_values_describe(){ +__conda_describe_existing_config_values(){ local -a config_values search_term search_term="$1" - config_values=($( __conda_config_values $search_term )) + config_values=($( __conda_existing_config_values $search_term )) if [ "${#config_values}" == 0 ] ; then _message "no values found for '$search_term'!" else @@ -124,7 +124,7 @@ __conda_config_values_describe(){ fi } -__conda_boolean_config_value(){ +__conda_describe_boolean_config_values(){ local -a config_values config_values=(True False) _describe -t config_values 'boolean configuration values' config_values @@ -133,12 +133,12 @@ __conda_boolean_config_value(){ __conda_channels(){ local -a channels - channels=$( __conda_config_values "channels" ) + channels=$( __conda_existing_config_values "channels" ) channels+=(system) _describe -t channels 'conda channels' channels } -boolean_config_options=( +__conda_boolean_config_keys=( 'add_binstar_token' 'always_yes' 'allow_softlinks' @@ -152,7 +152,7 @@ boolean_config_options=( 'ssl_verify' ) -list_config_options=( +__conda_list_config_keys=( 'channels' 'disallow' 'create_default_packages' @@ -160,21 +160,20 @@ list_config_options=( 'envs_dirs' ) -__boolean_conda_config(){ - _describe -t boolean_config_options 'boolean keys' boolean_config_options +__conda_config_keys=($__conda_boolean_config_keys $__conda_list_config_keys) + +__conda_describe_boolean_config_keys(){ + _describe -t __conda_boolean_config_keys 'boolean keys' __conda_boolean_config_keys } -__list_conda_config(){ - _describe -t list_config_options 'list keys' list_config_options +__conda_describe_list_config_keys(){ + _describe -t __conda_list_config_keys 'list keys' __conda_list_config_keys } -config_options=($boolean_config_options $list_config_options) - -__conda_config(){ - _describe -t config_options 'conda configuration keys' config_options +__conda_describe_config_keys(){ + _describe -t __conda_config_keys 'conda configuration keys' __conda_config_keys } - __conda_commands(){ local -a package maint environment help config special package=( @@ -352,8 +351,8 @@ case $state in # this allows completing multiple keys whet --get is given local -a last_item get_opts last_item=$line[$CURRENT-1] - if [[ ${line[(r)--get]} == --get ]] && [[ ${config_options[(r)$last_item]} == $last_item ]] ; then - get_opts=('*:keys:__conda_config') + if [[ ${line[(r)--get]} == --get ]] && [[ ${__conda_config_keys[(r)$last_item]} == $last_item ]] ; then + get_opts=('*:keys:__conda_describe_config_keys') else get_opts='' fi @@ -361,11 +360,11 @@ case $state in $json_opts \ '--system[write to the system .condarc file]' \ '--file[write to the given file.]:file:_path_files' \ - '( --add --set --remove --remove-key)--get[get the configuration value]:key:__conda_config' \ - '(--get --set --remove --remove-key)--add[add one configuration value to a list key]:list key:__list_conda_config:value:' \ - '(--get --add --remove --remove-key)--set[set a boolean key]:boolean key:__boolean_conda_config:value:__conda_boolean_config_value' \ - '(--get --add --set --remove-key)--remove[remove a configuration value from a list key]:list key:__list_conda_config:value:{__conda_config_values_describe '$last_item'}' \ - '(--get --add --set --remove )--remove-key[remove a configuration key (and all its values)]:key:__conda_config' \ + '( --add --set --remove --remove-key)--get[get the configuration value]:key:__conda_describe_config_keys' \ + '(--get --set --remove --remove-key)--add[add one configuration value to a list key]:list key:__conda_describe_list_config_keys:value:' \ + '(--get --add --remove --remove-key)--set[set a boolean key]:boolean key:__conda_describe_boolean_config_keys:value:__conda_describe_boolean_config_values' \ + '(--get --add --set --remove-key)--remove[remove a configuration value from a list key]:list key:__conda_describe_list_config_keys:value:{__conda_describe_existing_config_values '$last_item'}' \ + '(--get --add --set --remove )--remove-key[remove a configuration key (and all its values)]:key:__conda_describe_config_keys' \ '(-f --force)'{-f,--force}'[write to the config file using the yaml parser]' \ $get_opts ;; From 0f603dd284774037358ebad418867994c47f69c1 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Sat, 14 Feb 2015 18:33:15 +0100 Subject: [PATCH 14/17] localize some more variables --- _conda | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/_conda b/_conda index 29e27be..cbbb54c 100644 --- a/_conda +++ b/_conda @@ -138,6 +138,8 @@ __conda_channels(){ _describe -t channels 'conda channels' channels } +local -a __conda_boolean_config_keys __conda_list_config_keys __conda_config_keys + __conda_boolean_config_keys=( 'add_binstar_token' 'always_yes' @@ -217,16 +219,12 @@ _conda_caching_policy() { (( $#oldp )) } -local -a opts +local -a opts help_opts json_opts env_opts channel_opts install_opts opts=( '(-h --help)'{-h,--help}'[show this help message and exit]' '(-V --version)'{-V,--version}'[show program''s version number and exit]' ) -_arguments -C $opts \ - ': :->command' \ - '*:: :->subcmd' - help_opts=( '(-h --help)'{-h,--help}'[show the help message and exit]' \ ) @@ -261,6 +259,10 @@ install_opts=( '--alt-hint[Use an alternate algorithm to generate an unsatisfiable hint]' \ ) +_arguments -C $opts \ + ': :->command' \ + '*:: :->subcmd' + case $state in (command) __conda_commands From 1b417173d14db46f3b8224ee23bed98128703e80 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Sat, 14 Feb 2015 18:35:23 +0100 Subject: [PATCH 15/17] uniform pseudo namespace --- _conda | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_conda b/_conda index cbbb54c..3e89378 100644 --- a/_conda +++ b/_conda @@ -72,7 +72,7 @@ __conda_envs(){ } __conda_packages_installed(){ - zstyle ":completion:${curcontext}:" cache-policy _conda_caching_policy + 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' ')) @@ -82,7 +82,7 @@ __conda_packages_installed(){ } __conda_packages_search(){ - zstyle ":completion:${curcontext}:" cache-policy _conda_caching_policy + 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 | @@ -213,7 +213,7 @@ __conda_commands(){ _describe -t special_commands "special commands" special } -_conda_caching_policy() { +__conda_caching_policy() { local -a oldp oldp=( "$1"(Nmh+12) ) # 12 hour (( $#oldp )) From a48a34102d116d4b1f877a3927a37f0797f1f612 Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Sat, 14 Feb 2015 18:50:53 +0100 Subject: [PATCH 16/17] complete only existing keys in --get --remove and --remove-key --- _conda | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/_conda b/_conda index 3e89378..e0e55e0 100644 --- a/_conda +++ b/_conda @@ -97,6 +97,43 @@ for k in parsed.keys(): _describe -t available_packages 'available packages' available_packages } +__conda_existing_config_keys(){ + local -a config_keys + config_keys=($(conda config --json --get | + python -c " +import json, sys +keys = json.load(sys.stdin)['get'].keys() +for k in keys: + print(k) + ")) + print -l $config_keys +} +__conda_describe_existing_config_keys(){ + local -a config_keys + config_keys=($( __conda_existing_config_keys )) + if [ "${#config_keys}" == 0 ] ; then + _message "no keys found!" + else + _describe -t config_keys 'existing configuration keys' config_keys + fi +} + +__conda_describe_existing_list_config_keys(){ + local -a config_keys existing_list_config_keys + config_keys=($( __conda_existing_config_keys )) + existing_list_config_keys=() + for k in $config_keys; do + if [[ ${__conda_list_config_keys[(r)$k]} == $k ]] ; then + existing_list_config_keys+=$k + fi + done + if [ "${#existing_list_config_keys}" == 0 ] ; then + _message "no keys found!" + else + _describe -t existing_list_config_keys 'existing list configuration keys' existing_list_config_keys + fi +} + __conda_existing_config_values(){ local -a config_values search_term search_term="$1" @@ -362,11 +399,11 @@ case $state in $json_opts \ '--system[write to the system .condarc file]' \ '--file[write to the given file.]:file:_path_files' \ - '( --add --set --remove --remove-key)--get[get the configuration value]:key:__conda_describe_config_keys' \ + '( --add --set --remove --remove-key)--get[get the configuration value]:key:__conda_describe_existing_config_keys' \ '(--get --set --remove --remove-key)--add[add one configuration value to a list key]:list key:__conda_describe_list_config_keys:value:' \ '(--get --add --remove --remove-key)--set[set a boolean key]:boolean key:__conda_describe_boolean_config_keys:value:__conda_describe_boolean_config_values' \ - '(--get --add --set --remove-key)--remove[remove a configuration value from a list key]:list key:__conda_describe_list_config_keys:value:{__conda_describe_existing_config_values '$last_item'}' \ - '(--get --add --set --remove )--remove-key[remove a configuration key (and all its values)]:key:__conda_describe_config_keys' \ + '(--get --add --set --remove-key)--remove[remove a configuration value from a list key]:list key:__conda_describe_existing_list_config_keys:value:{__conda_describe_existing_config_values '$last_item'}' \ + '(--get --add --set --remove )--remove-key[remove a configuration key (and all its values)]:key:__conda_describe_existing_config_keys' \ '(-f --force)'{-f,--force}'[write to the config file using the yaml parser]' \ $get_opts ;; From 056b33960e45249c92437812c1f05d665b818e9c Mon Sep 17 00:00:00 2001 From: Valentin Haenel Date: Sat, 14 Feb 2015 18:55:46 +0100 Subject: [PATCH 17/17] update the changelog --- _conda | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/_conda b/_conda index e0e55e0..7fb39a1 100644 --- a/_conda +++ b/_conda @@ -29,7 +29,13 @@ # # * v0.3 # -# * +# * overhaul of the completion for config +# +# * complete only existing keys +# * complete only existing values +# * differentiate between list and boolean config +# * reader and writer options mutually exclusive +# * complete multiple keys for --get # # * v0.2 # @@ -44,10 +50,6 @@ # ---- # # * Subcommand grouping is still alpha. -# * Completion for 'conda config' is somewhat incomplete -# * 'conda config --get' only completes a single option. -# * 'conda config --add' completes only the key, not the value. -# * Similar issues for other options. # * Example of activating cache only for conda completion # * Make cache policy configurable # * Completion for version numbers is entirely missing: @@ -59,7 +61,6 @@ # * Completion of channels is rudimentary, conda isn't queried for defined # channels. # * Configuration for external commands, e.g. 'build' is entirely missing. -# * Seperate boolean and list options for 'config' # * Properly handle package specs on the command line local state line context