-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path_blinky
146 lines (131 loc) · 5.2 KB
/
_blinky
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
#compdef blinky
# Copyright (C) 2018 Paul Seyfert <[email protected]>
#
# This software is distributed under the terms of the GNU General Public
# Licence version 3 (GPL Version 3), copied verbatim in the file "LICENSE".
# heavily inspired by the _pacman completion
local -a _blinky_opts_all _blinky_opts_install _blinky_opts_build
_blinky_opts_all=(
'(-v --verbose)'{-v,--verbose}'[Be more verbose]'
)
_blinky_opts_install=(
'--asdeps[If packages are installed, install them as dependencies]'
)
_blinky_opts_build=(
"--keep-sources[Keep sources]:keep which sources:((none\:'keep no sources' skipped\:'keep sources of skipped packages' all\:'keep all sources'))"
'--build-only[Only build, do not install anything]'
'--difftool=[specify tool used for diffing]:difftool: _command_names -e'
'--force-review[Force review even if exact copies of the files have already been reviewed positively]'
'*--ignore[ignore package]:package: _blinky_completions_all_packages'
'--keep-builddeps[Do not uninstall previously uninstalled makedeps after building]'
'--makepkg.conf[Configuration file for makepkg]:makpkg.conf: _files'
)
# provides completions for packages available from repositories
# these can be specified as either 'package' or 'repository/package'
_blinky_completions_local_packages() {
local -a seq sep cmd packages repositories packages_long
# ${(f)"$(pacman -Qm)"} split the response from `pacman -Qm` by line break
# ${.....................[@]%%\ *} strip away the largest match of trailing " *"
packages=( ${${(f)"$(pacman -Qm)"}[@]%%\ *} )
typeset -U packages
_wanted packages expl "installed non-repository packages" compadd "${(@)packages}"
}
_blinky_completions_all_packages() {
local -i minimum_package_name_length
# steer minimum package name length for launching package search
# set with:
# zstyle :completion:expand-word:complete:blinky:pkgcomp: numbers 4
zstyle -s :completion:expand-word:complete:blinky:pkgcomp: numbers minimum_package_name_length || minimum_package_name_length=4
if [[ $#PREFIX -lt $minimum_package_name_length || $PREFIX = -* ]]; then
_message "not completing package names with less than $minimum_package_name_length characters provided"
return 0
fi
matches=( $(blinky -complete $PREFIX) )
typeset -U packages
_wanted packages expl "packages" compadd "${(@)matches}"
}
# main dispatcher
_blinky_zsh_comp() {
local -a _blinky_actions _full_actions _exclude_rules
# commands (all mutually exclusive)
_blinky_actions=(
{-h,--help}'[Display usage]'
'-S[Install package(s) from AUR]'
'-Sr[Reinstall package(s) from AUR (including rebuild)]'
'-Srr[Reinstall package(s) and dependencies from AUR (including rebuild)]'
'-Ss[Search for package(s) in AUR]'
'-Si[Get detailed info on packages in AUR]'
'-Syu[Upgrade all out-of-date AUR-packages]'
'-Sc[Clean cache of all uninstalled package files]'
'-Scc[Clean cache of all package files, including installed]'
)
# remove longest trailing "[*" from every element and pack () around
_exclude_rules='('"${_blinky_actions[@]%%\[*}"')'
# prefix every element from _blinky_actions with _exclude_rules this results in something like
#
# '(-S -Sr -Srr)-S[Install package(s) from AUR]'
# '(-S -Sr -Srr)-Sr[Reinstall package(s) from AUR (including rebuild)]'
# '(-S -Sr -Srr)-Srr[Reinstall package(s) and dependencies from AUR (including rebuild)]'
#
# this is the syntax for _arguments to say "do not suggest any of ( <these> ) once <THAT> is present and explain it as [ <text> ]
_full_actions=($_exclude_rules${^_blinky_actions})
local -a cmd;
local tmp
# ${(M)words:#-S*} : array of all the elements of words, that match -S*
# ${................#-} remove leading -
# ${.....................:#-*} : array of all the elements that don't match -*
# i.e. args is all that starts with a single - and that single - removed
cmd=( ${${${(M)words:#-S*}#-}:#-*} )
case $cmd[1] in
# Depending on the command that is run, do not offer flags that will be ignored
Sc*)
_arguments : \
$_blinky_opts_all[@] \
$_full_actions[@]
;;
Ss)
_arguments : \
$_blinky_opts_all[@] \
$_full_actions[@] \
'*:search text'
;;
Sr*)
_arguments : \
$_blinky_opts_all[@] \
$_blinky_opts_build[@] \
$_blinky_opts_install[@] \
$_full_actions[@] \
'*:package:_blinky_completions_local_packages'
;;
Si)
_arguments : \
$_blinky_opts_all[@] \
$_full_actions[@] \
'*:package:_blinky_completions_all_packages'
;;
Syu)
_arguments : \
$_blinky_opts_all[@] \
$_blinky_opts_build[@] \
$_full_actions[@]
;;
S*)
_arguments : \
$_blinky_opts_all[@] \
$_blinky_opts_build[@] \
$_blinky_opts_install[@] \
$_full_actions[@] \
'*:package:_blinky_completions_all_packages'
;;
*)
# else, (i.e. no -S command on the current command line)
# We offer all possible flags
_arguments : \
$_blinky_opts_all[@] \
$_blinky_opts_build[@] \
$_blinky_opts_install[@] \
$_full_actions[@]
;;
esac
}
_blinky_zsh_comp "$@"