Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement example completion for zsh #9939

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/etc/_cargo
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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' \
Expand Down Expand Up @@ -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]' \
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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