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)
This commit is contained in:
bors 2021-09-22 16:08:27 +00:00
commit 0121d66aa2

View File

@ -39,7 +39,7 @@ _cargo() {
# appropriate command's `_arguments` where appropriate.
command_scope_spec=(
'(--bin --example --test --lib)--bench=[specify benchmark name]: :_cargo_benchmark_names'
'(--bench --bin --test --lib)--example=[specify example name]:example name'
'(--bench --bin --test --lib)--example=[specify example name]:example name:_cargo_example_names'
'(--bench --example --test --lib)--bin=[specify binary name]:binary name'
'(--bench --bin --example --test)--lib=[specify library name]:library name'
'(--bench --bin --example --lib)--test=[specify test name]:test name'
@ -148,7 +148,7 @@ _cargo() {
'--bin=[only install the specified binary]:binary' \
'--branch=[branch to use when installing from git]:branch' \
'--debug[build in debug mode instead of release mode]' \
'--example=[install the specified example instead of binaries]:example' \
'--example=[install the specified example instead of binaries]:example:_cargo_example_names' \
'--git=[specify URL from which to install the crate]:url:_urls' \
'--path=[local filesystem path to crate to install]: :_directories' \
'--rev=[specific commit to use when installing from git]:commit' \
@ -222,7 +222,7 @@ _cargo() {
run)
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'--example=[name of the bin target]:name' \
'--example=[name of the bin target]:name:_cargo_example_names' \
'--bin=[name of the bin target]:name' \
'(-p --package)'{-p+,--package=}'[specify package with the target to run]:package:_cargo_package_names' \
'--release[build in release mode]' \
@ -267,7 +267,7 @@ _cargo() {
'(--doc --bin --example --test --bench)--lib[only test library]' \
'(--lib --bin --example --test --bench)--doc[only test documentation]' \
'(--lib --doc --example --test --bench)--bin=[binary name]' \
'(--lib --doc --bin --test --bench)--example=[example name]' \
'(--lib --doc --bin --test --bench)--example=[example name]:_cargo_example_names' \
'(--lib --doc --bin --example --bench)--test=[test name]' \
'(--lib --doc --bin --example --test)--bench=[benchmark name]' \
'*: :_default'
@ -416,4 +416,11 @@ _cargo_benchmark_names() {
_cargo_names_from_array "bench"
}
_cargo_example_names() {
if [[ -d examples ]]; then
local -a files=(${(@f)$(echo examples/*.rs(:t:r))})
_values 'example' "${files[@]}"
fi
}
_cargo