22
33autoload -U regexp-replace
44
5- zstyle -T ':completion:*:*:cargo:*' tag-order && \
6- zstyle ':completion:*:*:cargo:*' tag-order 'common-commands'
7-
85_cargo() {
96local context state state_descr line
107typeset -A opt_args
@@ -24,14 +21,10 @@ _arguments \
2421 '(+beta +nightly)+stable[use the stable toolchain]' \
2522 '(+stable +nightly)+beta[use the beta toolchain]' \
2623 '(+stable +beta)+nightly[use the nightly toolchain]' \
27- '1: :->command ' \
24+ '1: :_cargo_cmds ' \
2825 '*:: :->args'
2926
3027case $state in
31- command)
32- _alternative 'common-commands:common:_cargo_cmds' 'all-commands:all:_cargo_all_cmds'
33- ;;
34-
3528 args)
3629 case $words[1] in
3730 bench)
@@ -426,44 +419,9 @@ esac
426419}
427420
428421_cargo_cmds(){
429- local -a commands;commands=(
430- 'bench:execute all benchmarks of a local package'
431- 'build:compile the current package'
432- 'check:check the current package without compiling'
433- 'clean:remove generated artifacts'
434- 'doc:build package documentation'
435- 'fetch:fetch package dependencies'
436- 'generate-lockfile:create lockfile'
437- 'git-checkout:git checkout'
438- 'help:get help for commands'
439- 'init:create new package in current directory'
440- 'install:install a Rust binary'
441- 'locate-project:print "Cargo.toml" location'
442- 'login:login to remote server'
443- 'metadata:the metadata for a package in json'
444- 'new:create a new package'
445- 'owner:manage the owners of a crate on the registry'
446- 'package:assemble local package into a distributable tarball'
447- 'pkgid:print a fully qualified package specification'
448- 'publish:upload package to the registry'
449- 'read-manifest:print manifest in JSON format'
450- 'run:run the main binary of the local package'
451- 'rustc:compile a package and all of its dependencies'
452- 'rustdoc:build documentation for a package'
453- 'search:search packages on crates.io'
454- 'test:execute all unit and tests of a local package'
455- 'uninstall:remove a Rust binary'
456- 'update:update dependencies'
457- 'verify-project:check Cargo.toml'
458- 'version:show version information'
459- 'yank:remove pushed file from index'
460- )
461- _describe -t common-commands 'common commands' commands
462- }
463-
464- _cargo_all_cmds(){
465- local -a commands;commands=($(cargo --list))
466- _describe -t all-commands 'all commands' commands
422+ local -a commands
423+ commands=( ${${${(M)"${(f)$(cargo --list)}":# *}/ ##/}/ ##/:} )
424+ _describe 'command' commands
467425}
468426
469427
0 commit comments