Skip to content

Commit 504f440

Browse files
committed
Tweak Zsh completions and allow completion on ports tree
- Ensure that mutually exclusive options are not both completed. For example, in the '-a' specification for the 'bulk' action shown below, the (-f *) indicates that if '-a' has been specified, then do not complete either '-f' or a ports tree. '(-f *)-a[build the whole ports tree]' - Ensure that mandatory arguments are properly completed. For example, in the '-p' specifications show below, in the first form, the ports tree is optional and in the second form it is mandatory. -p+[specifies which ports tree to use]::tree:_poudriere_pt -p+[specifies which ports tree to use]:tree:_poudriere_pt
1 parent b2b6178 commit 504f440

File tree

1 file changed

+88
-55
lines changed

1 file changed

+88
-55
lines changed

completions/zsh/_poudriere

Lines changed: 88 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,38 @@ _poudriere_pt() {
88
_values "poudriere portstrees" ${${(f)"$(${service} ports -lq)"}%% *}
99
}
1010

11+
_poudriere_direct_port() {
12+
# Find a ports tree to complete ports
13+
local prev_word=
14+
local ports_tree=
15+
local w
16+
17+
# Determine whether a tree has already been specified with -p
18+
for w in ${words[@]}; do
19+
if [[ $w == -p ]]; then
20+
prev_word=-p
21+
elif [[ $prev_word == -p ]]; then
22+
ports_tree="$w"
23+
break
24+
fi
25+
done
26+
27+
# Determine whether the default tree is present
28+
if [[ -z $ports_tree ]] && poudriere ports -l | grep -q '^default '; then
29+
ports_tree=default
30+
elif [[ -z $ports_tree ]]; then
31+
return
32+
fi
33+
34+
local ports_tree_path="$(poudriere ports -lq | awk -v tree=$ports_tree '{if (match($1, tree)) {print $5}}')"
35+
36+
# complete port
37+
_path_files -W ${ports_tree_path} -/
38+
}
39+
1140
_bulk=(
12-
'-a[build the whole ports tree]'
13-
'-f[get the list of ports to build from a file]:name of file:_files'
41+
'(-f *)-a[build the whole ports tree]'
42+
'(-a *)-f[get the list of ports to build from a file]:name of file:_files'
1443
'-B[what buildname to use]:buildname'
1544
'-c[clean all the previously built binary packages and logs]'
1645
'-C[clean only the packages listed on the command line or -f file]'
@@ -24,13 +53,14 @@ _bulk=(
2453
'-T[try to build broken ports anyway]'
2554
'-F[only fetch from original master_site (skip FreeBSD mirrors)]'
2655
'-S[don\x27t recursively rebuild packages affected by other packages requiring incremental rebuild]'
27-
'-J[run n jobs in parallel, and optionally run a different number of jobs in parallel while preparing the build]::'
28-
'-j[run only on the given jail]::jail name:_poudriere_jail'
56+
'-J[run n jobs in parallel, and optionally run a different number of jobs in parallel while preparing the build]:'
57+
'-j[run only on the given jail]:jail name:_poudriere_jail'
2958
'-N[do not build package repository or INDEX when build completed]'
30-
'-p[specify on which ports tree the bulk build will be done]::tree:_poudriere_pt'
59+
'-p[specify on which ports tree the bulk build will be done]:tree:_poudriere_pt'
3160
'-v[be verbose; show more information. Use twice to enable debug output]'
3261
'-w[save WRKDIR on failed builds]'
33-
'-z[specify which SET to use]::'
62+
'-z[specify which SET to use]:'
63+
'(-a -f)*:cat/port:_poudriere_direct_port'
3464
)
3565

3666
_daemon=(
@@ -42,8 +72,8 @@ _daemon=(
4272
_distclean=(
4373
'-a[clean the whole ports tree]'
4474
'-f[get the list of ports to clean from a file]:name of file:_files'
45-
'-J[run n jobs in parallel]::'
46-
'-p[specify which ports tree to use for comparing to distfiles, can be specified multiple times]::tree:_poudriere_pt'
75+
'-J[run n jobs in parallel]:'
76+
'-p[specify which ports tree to use for comparing to distfiles, can be specified multiple times]:tree:_poudriere_pt'
4777
'-n[do not actually remove anything, just show what would be removed]::'
4878
'-v[be verbose; show more information. use twice to enable debug output]'
4979
'-y[assume yes when deleting and do not prompt for confirmation]::'
@@ -53,15 +83,15 @@ _image=(
5383
'-c[the content of the overlay directory will be copied into the image]:directory:_files'
5484
'-f[list of packages to install]:file:_files'
5585
'-h[the image hostname]:hostname:'
56-
'-j[jail]::jailname:_poudriere_jail'
86+
'-j[jail]:jailname:_poudriere_jail'
5787
'-m[build a miniroot image as well (for tar type images), and overlay this directory into the miniroot image]:directory:_files'
5888
'-n[the name of the generated image]:imagename:'
5989
'-o[image destination directory]:directory:_files'
60-
'-p[Ports tree]::tree:_poudriere_pt'
90+
'-p[Ports tree]:tree:_poudriere_pt'
6191
'-s[set the image size]:size:'
62-
'-t[type of image]::type:((iso iso+mfs iso+zmfs usb usb+mfs usb+zmfs rawdisk zrawdisk tar firmware rawfirmware embedded))'
92+
'-t[type of image]:type:((iso iso+mfs iso+zmfs usb usb+mfs usb+zmfs rawdisk zrawdisk tar firmware rawfirmware embedded))'
6393
'-X[file containing the list in cpdup format]:file:_files'
64-
'-z[set]::'
94+
'-z[set]:'
6595
)
6696

6797
_jail=(
@@ -72,82 +102,83 @@ _jail=(
72102
'(-c -d -i -l -k -u -r)-s[start a jail]'
73103
'(-c -d -i -l -s -u -r)-k[stop a jail]'
74104
'(-c -d -i -l -s -k -r)-u[update a jail]'
75-
'(-c -d -i -l -s -k -u)-r[rename a jail to name]::name'
105+
'(-c -d -i -l -s -k -u)-r[rename a jail to name]:name'
76106
'-b[build the OS (for use with -m src)]'
77107
'-q[quiet (do not print the header)]'
78-
'-J[run buildworld in parallel with n jobs]::'
79-
'-j[specifies the jailname]::jailname:_poudriere_jail'
80-
'-v[specify which version of FreeBSD to install in the jail]::version'
81-
'-a[indicates the TARGET_ARCH of the jail. Such as i386 or amd64]::arch:(amd64 i386)'
82-
'-f[fs name (tank/jails/myjail) if fs is "none" then do not create on ZFS]::fs:_files -/'
83-
'-K[build the jail with the kernel]::kernelname'
84-
'-M[mountpoint]::mountpoint:_files -/'
85-
'-m[when used with -c, overrides the default method for obtaining and building the jail.]::method:(allbsd ftp-archive ftp git http null src svn svn+file svn+http svn+https svn+ssh tar url)'
86-
'-P[specify a patch to apply to the source before building]::patch:_files -/'
87-
'-S[specify a path to the source tree to be used]::srcpath:_files -/'
108+
'-J[run buildworld in parallel with n jobs]:'
109+
'-j[specifies the jailname]:jailname:_poudriere_jail'
110+
'-v[specify which version of FreeBSD to install in the jail]:version'
111+
'-a[indicates the TARGET_ARCH of the jail. Such as i386 or amd64]:arch:(amd64 i386)'
112+
'-f[fs name (tank/jails/myjail) if fs is "none" then do not create on ZFS]:fs:_files -/'
113+
'-K[build the jail with the kernel]:kernelname'
114+
'-M[mountpoint]:mountpoint:_files -/'
115+
'-m[when used with -c, overrides the default method for obtaining and building the jail.]:method:(allbsd ftp-archive ftp git http null src svn svn+file svn+http svn+https svn+ssh tar url)'
116+
'-P[specify a patch to apply to the source before building]:patch:_files -/'
117+
'-S[specify a path to the source tree to be used]:srcpath:_files -/'
88118
'-D[do a full git clone without --depth]'
89-
'-t[version of FreeBSD to upgrade the jail to]::version'
90-
'-U[specify a url to fetch the sources (with method git and/or svn)]::url'
119+
'-t[version of FreeBSD to upgrade the jail to]:version'
120+
'-U[specify a url to fetch the sources (with method git and/or svn)]:url'
91121
'-x[build and setup native-xtools cross compile tools in jail when building for a different TARGET ARCH than the host]'
92-
'-C[clean remaining data existing in pourdiere data folder]::clean:(all cache logs packages wrkdirs)'
93-
'-p[specify which ports tree to start/stop the jail with]::tree:_poudriere_pt'
94-
'-z[specify which SET the jail to start/stop with]::set'
122+
'-C[clean remaining data existing in pourdiere data folder]:clean:(all cache logs packages wrkdirs)'
123+
'-p[specify which ports tree to start/stop the jail with]:tree:_poudriere_pt'
124+
'-z[specify which SET the jail to start/stop with]:set'
95125
)
96126

97127
_logclean=(
98128
'(-N)-a[remove all logfiles matching the filter]'
99129
'(-a)-N[how many logfiles to keep matching the filter per jail/tree/set combination]:count:'
100130
'-B[build name glob to match on]:glob:'
101-
'-j[which jail to use for log directories]::name:_poudriere_jail'
102-
'-p[specify which ports tree to use for log directories]::tree:_poudriere_pt'
131+
'-j[which jail to use for log directories]:name:_poudriere_jail'
132+
'-p[specify which ports tree to use for log directories]:tree:_poudriere_pt'
103133
'-n[do not actually remove anything, just show what would be removed]'
104134
'-v[be verbose; show more information]'
105135
'-y[assume yes when deleting and do not prompt for confirmation]'
106-
'-z[specify which SET to match for logs]::'
136+
'-z[specify which SET to match for logs]:'
107137
)
108138

109139
_options=(
110-
'-a[indicates the TARGET_ARCH if no jail is specified]::arch:(amd64 i386)'
140+
'-a[indicates the TARGET_ARCH if no jail is specified]:arch:(amd64 i386)'
111141
"(-C)-c[use 'make config' target]::"
112142
"(-c)-C[use 'make config-conditional' target]::"
113-
'-f[give the list of ports to set options]:name of file:_files'
114-
'-j[run on the given jail]::name:_poudriere_jail'
143+
'(*)-f[give the list of ports to set options]:name of file:_files'
144+
'-j[run on the given jail]:name:_poudriere_jail'
115145
'-n[do not configure/show/remove options of dependencies]::'
116-
'-p[specify on which ports tree the configuration will be done]::tree:_poudriere_pt'
146+
'-p[specify on which ports tree the configuration will be done]:tree:_poudriere_pt'
117147
'(-r)-s[show options instead of configuring them]::'
118148
'(-s)-r[show port options instead of configuring them]::'
119-
'-z[Specify which SET to use]::'
149+
'-z[Specify which SET to use]:'
150+
'(-f)*:cat/port:_poudriere_direct_port'
120151
)
121152

122153
_pkgclean=(
123154
'(-a -f)-A[remove all packages]'
124155
'(-A -f)-a[keep all known ports]'
125156
'(-A -a)-f[get the list of ports to keep from a file]:name of file:_files'
126-
'-j[which jail to use for packages]::jail name:_poudriere_jail'
127-
'-J[run n jobs in parallel]::'
157+
'-j[which jail to use for packages]:jail name:_poudriere_jail'
158+
'-J[run n jobs in parallel]:'
128159
'-n[do not actually remove anything, just show what would be removed]::'
129160
'-N[do not build the package repository when clean completed]'
130-
'-p[which ports tree to use for packages]::tree:_poudriere_pt'
161+
'-p[which ports tree to use for packages]:tree:_poudriere_pt'
131162
'-R[clean RESTRICTED packages after building]'
132163
'-v[be verbose; show more information. Use twice to enable debug output]'
133164
'-y[assume yes when deleting and do not confirm]::'
134-
'-z[specify which SET to use for packages]::'
165+
'-z[specify which SET to use for packages]:'
135166
)
136167

137168
_ports=(
138169
'(-d -u -l)-c[create a ports tree]'
139170
'(-c -u -l)-d[delete a ports tree]'
140171
'(-c -d -u)-l[lists all available ports trees]'
141172
'(-c -d -l)-u[update a ports tree]'
142-
'-U[url where to fetch the ports tree from]::'
143-
'-B[which branch to use for the svn or git methods]::'
173+
'-U[url where to fetch the ports tree from]:'
174+
'-B[which branch to use for the svn or git methods]:'
144175
'-F[When used with -c, only create the needed filesystems (for ZFS) and directories, but do not populate them.]'
145-
'-M[the path to the source of a ports tree]::path:_files -/'
146-
'-f[the name of the filesystem to create for the ports tree]::fs:_files -/'
176+
'-M[the path to the source of a ports tree]:path:_files -/'
177+
'-f[the name of the filesystem to create for the ports tree]:fs:_files -/'
147178
'-k[when used with -d, only unregister the ports tree without removing the files]'
148-
'-m[when used with -c, specify the method used to create the ports tree]::method:((git null portsnap svn svn+http svn+https svn+file svn+ssh))'
179+
'-m[when used with -c, specify the method used to create the ports tree]:method:((git null portsnap svn svn+http svn+https svn+file svn+ssh))'
149180
'-n[when used with -l, only print the name of the ports tree]'
150-
'-p[specifies the name of the ports tree to work on]::tree:_poudriere_pt'
181+
'-p[specifies the name of the ports tree to work on]:tree:_poudriere_pt'
151182
'-q[when used with -l, remove the header in the list view]'
152183
'-v[show more verbose output]'
153184
)
@@ -159,29 +190,31 @@ _status=(
159190
'-B[what buildname to use]:buildname'
160191
'-c[compact output]'
161192
'-H[do not print headers and separate fields by a single tab instead of arbitrary white space]'
162-
'-j[run on the given jail]::name:_poudriere_jail'
163-
'-p[specify on which ports tree to match for the build]::tree:_poudriere_pt'
193+
'-j[run on the given jail]:name:_poudriere_jail'
194+
'-p[specify on which ports tree to match for the build]:tree:_poudriere_pt'
164195
'-l[show logs instead of URL]'
165196
'-r[show results]'
166-
'-z[specify which SET to match for the build]::'
197+
'-z[specify which SET to match for the build]:'
167198
)
168199

169200
_testport=(
170-
'-j[run inside the given jail]::name:_poudriere_jail'
171-
'-B[What buildname to use]::'
201+
'-j[run inside the given jail]:name:_poudriere_jail'
202+
'(*)-o[Specify an origin in the portstree]:origin:_poudriere_direct_port'
203+
'-B[What buildname to use]:'
172204
'-c[run make config for the given port]::'
173205
'-i[interactive mode]'
174206
'-I[advanced interactive mode]'
175-
'-J[Run n jobs in parallel for dependencies, and optionally run a different number of jobs in parallel while preparing the build]::'
207+
'-J[Run n jobs in parallel for dependencies, and optionally run a different number of jobs in parallel while preparing the build]:'
176208
"-k[don't consider failures as fatal; find all failures]"
177209
'-n[show what will be done, but do not build any packages]'
178210
'-N[do not build package repository when build of dependencies completed]'
179-
'-p[specifies which ports tree to use]::tree:_poudriere_pt'
180-
'-P[use custom prefix]'
181211
"-S[don't recursively rebuild packages affected by other packages requiring incremental rebuild]"
212+
'-p[specifies which ports tree to use]:tree:_poudriere_pt'
213+
'-P[use custom prefix]:'
182214
'-v[be verbose; show more information]'
183215
'-w[save WRKDIR on failed builds]'
184-
'-z[specify which SET to use]::'
216+
'-z[specify which SET to use]:'
217+
'(-o *)*:cat/port:_poudriere_direct_port'
185218
)
186219

187220
_poudriere () {

0 commit comments

Comments
 (0)