-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_prenv
49 lines (44 loc) · 1.31 KB
/
_prenv
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
#compdef _prenv prenv
function _prenv() {
local -a subcmd
subcmds=(
'list:List projects in config'
'on:Activate project'
'off:Deactivate project'
'show:Show details about active project(s)'
'clear:Clear all projects'
'cat:Print config'
"edit:Edit config with ${EDITOR:-editor}"
'help:Show help'
)
local -a projects active_projects inactive_projects project
projects=($(yq -r 'keys |.[]' ~/.config/prenv.yaml))
# Remove active projects from all projects
active_projects=(${(@)_PRENV})
inactive_projects=(${(@)projects})
for project in ${(@)active_projects}; do
inactive_projects=(${(@)inactive_projects:#${project}})
done
_arguments -C \
'1: :{_describe commands subcmds}' \
'*::arg:_prenv_subcommand'
}
function _prenv_subcommand() {
case $line[1] in
list)
_arguments \
'-v[Show environement variables]' \
'-f[Filter for active projects]'
;;
on)
# FIXME: -p only as second argument
_arguments \
': :($inactive_projects)' \
'-p[Preserve active projects]'
;;
off)
_arguments ': :($active_projects)'
;;
esac
}
compdef _prenv prenv