From b8df3cbfd5fbcb673af2d34d6f57e3aeb3ecc810 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Thu, 23 Sep 2021 00:03:06 +0900 Subject: [PATCH] Implement example completion for zsh --- src/etc/_cargo | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/etc/_cargo b/src/etc/_cargo index f8107729583..6ac0513ee69 100644 --- a/src/etc/_cargo +++ b/src/etc/_cargo @@ -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