Skip to content

Commit 0121d66

Browse files
committed
Auto merge of #9939 - syohex:zsh-example-completion, r=ehuss
Implement example completion for zsh Related issue #8871 #### Demo ![cargo_example_complete](https://user-images.githubusercontent.com/554281/134369988-c1d1d83e-0d61-4b8f-9b1d-ca5ca75e3723.gif)
2 parents 702a280 + b8df3cb commit 0121d66

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/etc/_cargo

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ _cargo() {
3939
# appropriate command's `_arguments` where appropriate.
4040
command_scope_spec=(
4141
'(--bin --example --test --lib)--bench=[specify benchmark name]: :_cargo_benchmark_names'
42-
'(--bench --bin --test --lib)--example=[specify example name]:example name'
42+
'(--bench --bin --test --lib)--example=[specify example name]:example name:_cargo_example_names'
4343
'(--bench --example --test --lib)--bin=[specify binary name]:binary name'
4444
'(--bench --bin --example --test)--lib=[specify library name]:library name'
4545
'(--bench --bin --example --lib)--test=[specify test name]:test name'
@@ -148,7 +148,7 @@ _cargo() {
148148
'--bin=[only install the specified binary]:binary' \
149149
'--branch=[branch to use when installing from git]:branch' \
150150
'--debug[build in debug mode instead of release mode]' \
151-
'--example=[install the specified example instead of binaries]:example' \
151+
'--example=[install the specified example instead of binaries]:example:_cargo_example_names' \
152152
'--git=[specify URL from which to install the crate]:url:_urls' \
153153
'--path=[local filesystem path to crate to install]: :_directories' \
154154
'--rev=[specific commit to use when installing from git]:commit' \
@@ -222,7 +222,7 @@ _cargo() {
222222

223223
run)
224224
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
225-
'--example=[name of the bin target]:name' \
225+
'--example=[name of the bin target]:name:_cargo_example_names' \
226226
'--bin=[name of the bin target]:name' \
227227
'(-p --package)'{-p+,--package=}'[specify package with the target to run]:package:_cargo_package_names' \
228228
'--release[build in release mode]' \
@@ -267,7 +267,7 @@ _cargo() {
267267
'(--doc --bin --example --test --bench)--lib[only test library]' \
268268
'(--lib --bin --example --test --bench)--doc[only test documentation]' \
269269
'(--lib --doc --example --test --bench)--bin=[binary name]' \
270-
'(--lib --doc --bin --test --bench)--example=[example name]' \
270+
'(--lib --doc --bin --test --bench)--example=[example name]:_cargo_example_names' \
271271
'(--lib --doc --bin --example --bench)--test=[test name]' \
272272
'(--lib --doc --bin --example --test)--bench=[benchmark name]' \
273273
'*: :_default'
@@ -416,4 +416,11 @@ _cargo_benchmark_names() {
416416
_cargo_names_from_array "bench"
417417
}
418418

419+
_cargo_example_names() {
420+
if [[ -d examples ]]; then
421+
local -a files=(${(@f)$(echo examples/*.rs(:t:r))})
422+
_values 'example' "${files[@]}"
423+
fi
424+
}
425+
419426
_cargo

0 commit comments

Comments
 (0)