forked from nix-community/nix-zsh-completions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
_nix-env
162 lines (151 loc) · 5.84 KB
/
_nix-env
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#compdef nix-env
#autoload
emulate -L zsh
setopt extendedglob
local context state state_descr line
typeset -A opt_args
_nix-common-options
local -a _1st_arguments
_1st_arguments=(
'(main_options)'{--install,-i}"[Install package]"
'(main_options)'{--upgrade,-u}"[Upgrade package]"
'(main_options)'{--uninstall,-e}"[Uninstall package]"
'(main_options)'--set-flag'[Modify meta attribute of installed package]:Name:->flag_name:Value:->flag_value:*:Packages: _nix_installed_packages'
'(main_options)'{--query,-q}"[List information about derivations]"
'(main_options)'{--switch-profile,-S}"[Set the current profile path]"
"(main_options)--list-generations[Print a list of all generations in the active profile]"
"(main_options)--delete-generations[Delete specified generations]"
'(main_options)'{--switch-generation,-G}"[Activate specified generation]"
"(main_options)--rollback[Switch to the previous generation of active profile]"
)
local -a _nix_env_common_opts
_nix_env_common_opts=(
$_nix_common_opts \
'(--profile -p)'{--profile,-p}'[Specify the profile to use]:Path:_nix_profiles'\
$_nix_dry_run \
'--system-filter[Only show derivations matching the specified platform]:system:_nix_systems'\
)
local -a _nix_env_b
_nix_env_b=('(--prebuilt-only -b)'{--prebuilt-only,-b}'[Fail if there is no pre-built binary available]')
local _nix_env_from_profile
_nix_env_from_profile='--from-profile[Fetch store paths from another profile]:Profile:_nix_profiles'
# Workaround:
# opt_args doesn't contain the first option
# so can't detect stacked options like '-iA'
local expect_attr_paths=false
local opt
for opt in $words; do
case $opt in
--attr|-[^-]#A[^-]#)
expect_attr_paths=true
;;
esac
done
local -a command_options=()
# Look for a main option in the input and setup command_options appropriately
for opt in $words; do
case "$opt" in
--install|-[^-]#i[^-]#)
command_options=(
${_nix_env_common_opts:#'(--attr -A)'*}
'(--attr -A)'{--attr,-A}'[Specify packages by attribute path instead of name]'
$_nix_env_b
$_nix_env_from_profile
'(--preserve-installed -P)'{--preserve-installed,-P}'[Do not remove derivations with the same name]'
'(--remove-all -r)'{--remove-all,-r}'[Remove all previously installed packages prior to installing]'
'*:Package:{if $expect_attr_paths; then
_nix_complete_attr_paths;
else
_nix_installed_packages "(use -A/--attr to access all packages)"
fi}')
break
;;
--upgrade|-[^-]#u[^-]#)
command_options=(
$_nix_env_common_opts
$_nix_env_b
$_nix_env_from_profile
'(-lt -leq -eq --always)--lt[Upgrade derivations with newer versions (default)]'
'(-lt -leq -eq --always)--leq[Upgrade derivations with the same or newer version]'
'(-lt -leq -eq --always)--eq[Upgrade derivations with equivalent versions]'
'(-lt -leq -eq --always)--always[Upgrade even if version number decreases]'
'*:Packages: _nix_installed_packages')
break
;;
--uninstall|-[^-]#e[^-]#)
command_options=(
${_nix_env_common_opts:#'(--attr -A)'*}
'*::Packages: _nix_installed_packages')
break
;;
--set-flag)
break
;;
--query|-[^-]#q[^-]#)
command_options=(
$_nix_env_common_opts
'(--available -a)'{--available,-a}'[display all installable derivations]'
$_nix_env_b
'(--status -s)'{--status,-s}'[print status of derivation]'
'(--attr-path -p)'{--attr-path,-p}'[print attribute path of derivations]'
'--no-name[suppress printing of name attribute]'
'(--compare-versions -c)'{--compare-versions,-c}'[compare installed and available version]'
'--system[print system attribute]'
'--drv-path[print store derivation path]'
'--out-path[print output path]'
'--description[print description]'
'--xml[print output as xml]'
'--json[print output as json]'
'--meta[Print all meta attributes: only available with --xml]')
break
;;
--switch-profile|-[^-]#S[^-]#)
command_options=($_nix_env_common_opts ':Profile:_nix_profiles')
break
;;
--delete-generations)
command_options=($_nix_env_common_opts '*::Generations:_nix_generations')
break
;;
--switch-generation|-[^-]#G[^-]#)
command_options=($_nix_env_common_opts '::Generations:_nix_generations')
break
;;
esac
done
# Let _arguments handle the rest, with _1st_arguments being mutually exclusive
# under the main_options group
_arguments -s $command_options \
'*'{--file,-f}'[Specify Nix expression used to obtain derivations]:Path to file:_nix_path'\
$_nix_boilerplate_opts \
+ main_options \
$_1st_arguments
# Handle the --set-flag option
case $state in
flag_name)
local -a _set_flag_attrs=(
'priority:Resolve package name conflicts'
'keep:Prevent package from being upgraded'
'active:Package is symlinked to profile'
)
_describe -t commands "Package flag" _set_flag_attrs
break
;;
flag_value)
local flag_name=$words[$(($CURRENT - 1))]
case $flag_name in
priority)
_message "Number, lower priority values denote a higher priority"
break
;;
keep)
_values "TF" true false
break
;;
active)
_values "TF" true false
break
;;
esac
;;
esac