-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathconda.sh
83 lines (71 loc) · 2.2 KB
/
conda.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
_patch_help() {
if [[ "$*" == "conda" ]] \
|| [[ "$*" == "conda env" ]] \
; then
$@ --help | \
sed '/^positional arguments:/,+1 c\commands:' | \
sed '/(legacy):/,/^$/ d'
elif [[ "$*" == "conda shell" ]]; then
:;
else
$@ --help | \
sed -e 's/^\(\s\+-\S\+\)\( \S\+\)\+, -/\1 -/' \
-e 's/{\(\S\+\(,\S\+\)\+\)},\?/\1/' \
-e '/\S\+\(,\S\+\)\{1,\}/ s/,/|/g' \
fi
}
_patch_table() {
table="$( \
_patch_table_edit_options '--name;[`_choice_env_var`]' \
)"
if [[ "$*" == "conda config" ]]; then
echo "$table" | \
_patch_table_edit_options \
'--add;[`_choice_config_kv`]' \
'--append;[`_choice_config_kv`]' \
'--describe;[`_choice_config_key`]' \
'--get;[`_choice_config_key`]' \
'--prepend;[`_choice_config_kv`]' \
'--remove;[`_choice_config_kv`]' \
'--remove-key;[`_choice_config_key`]' \
'--set;[`_choice_config_kv`]' \
'--show;[`_choice_config_key`]' \
elif [[ "$*" == "conda init" ]]; then
echo "$table" | \
_patch_table_edit_arguments ';;' 'SHELLS;*[bash|fish|powershell|tcsh|xonsh|zsh]'
elif [[ "$*" == "conda remove" ]] \
|| [[ "$*" == "conda update" ]] \
; then
echo "$table" | \
_patch_table_edit_arguments ';;' 'package_name;[`_choice_package`]'
else
echo "$table"
fi
}
_choice_env_var() {
conda info --envs | gawk '{if(match($0, /^([^# ]+)[ *]+(.*)$/, arr)) { print arr[1] "\t" arr[2] }}'
}
_choice_config_key() {
conda config --show | yq -p yaml 'keys | .[]'
}
_choice_config_kv() {
if _helper_check_config_flag 1; then
_choice_config_key
fi
}
_choice_package() {
conda $(_argc_util_param_select_options --prefix --name) list --json | yq '.[] | .name + " " + .version'
}
_helper_check_config_flag() {
num="$1"
if [[ "${#argc_add[@]}" == "$num" ]] \
|| [[ "${#argc_append[@]}" == "$num" ]] \
|| [[ "${#argc_prepend[@]}" == "$num" ]] \
|| [[ "${#argc_remove[@]}" == "$num" ]] \
|| [[ "${#argc_set[@]}" == "$num" ]] \
; then
return 0
else
return 1
fi
}