From 6a61ca59890eaf5988aac8242c6f838e4dd48973 Mon Sep 17 00:00:00 2001 From: relrelb Date: Fri, 1 Oct 2021 11:14:45 +0300 Subject: [PATCH] Add shell completion for shorthand commands Currently `cargo` has shell completion for most (if not all) builtin commands such as `build`, `run`, `check` etc. However, it doesn't have shell completion for the short forms of these commands, such as `b`, `r`, `c` etc. This commit adds both bash and zsh completions for command shorthands. Fixes #9086. --- src/etc/_cargo | 10 +++++----- src/etc/cargo.bashcomp.sh | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/etc/_cargo b/src/etc/_cargo index 6ac0513ee69..5356313b6d2 100644 --- a/src/etc/_cargo +++ b/src/etc/_cargo @@ -77,7 +77,7 @@ _cargo() { '*:args:_default' ;; - build) + build | b) _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \ '--all-targets[equivalent to specifying --lib --bins --tests --benches --examples]' \ "${command_scope_spec[@]}" \ @@ -86,7 +86,7 @@ _cargo() { '--build-plan[output the build plan in JSON]' \ ;; - check) + check | c) _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \ '--all-targets[equivalent to specifying --lib --bins --tests --benches --examples]' \ "${command_scope_spec[@]}" \ @@ -101,7 +101,7 @@ _cargo() { '--doc[clean just the documentation directory]' ;; - doc) + doc | d) _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \ '--no-deps[do not build docs for dependencies]' \ '--document-private-items[include non-public items in the documentation]' \ @@ -220,7 +220,7 @@ _cargo() { _arguments -s -S $common $manifest ;; - run) + run | r) _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \ '--example=[name of the bin target]:name:_cargo_example_names' \ '--bin=[name of the bin target]:name' \ @@ -255,7 +255,7 @@ _cargo() { '*: :_guard "^-*" "query"' ;; - test) + test | t) _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \ '--test=[test name]: :_cargo_test_names' \ '--no-fail-fast[run all tests regardless of failure]' \ diff --git a/src/etc/cargo.bashcomp.sh b/src/etc/cargo.bashcomp.sh index 5859d33be5c..c61f3eed29b 100644 --- a/src/etc/cargo.bashcomp.sh +++ b/src/etc/cargo.bashcomp.sh @@ -50,9 +50,12 @@ _cargo() local opt___nocmd="$opt_common -V --version --list --explain" local opt__bench="$opt_common $opt_pkg_spec $opt_feat $opt_mani $opt_lock $opt_jobs $opt_targets --message-format --target --no-run --no-fail-fast --target-dir" local opt__build="$opt_common $opt_pkg_spec $opt_feat $opt_mani $opt_lock $opt_jobs $opt_targets --message-format --target --release --profile --target-dir" + local opt__b="$opt__build" local opt__check="$opt_common $opt_pkg_spec $opt_feat $opt_mani $opt_lock $opt_jobs $opt_targets --message-format --target --release --profile --target-dir" + local opt__c="$opt__check" local opt__clean="$opt_common $opt_pkg $opt_mani $opt_lock --target --release --doc --target-dir --profile" local opt__doc="$opt_common $opt_pkg_spec $opt_feat $opt_mani $opt_lock $opt_jobs --message-format --bin --bins --lib --target --open --no-deps --release --document-private-items --target-dir --profile" + local opt__d="$opt__doc" local opt__fetch="$opt_common $opt_mani $opt_lock --target" local opt__fix="$opt_common $opt_pkg_spec $opt_feat $opt_mani $opt_jobs $opt_targets $opt_lock --release --target --message-format --broken-code --edition --edition-idioms --allow-no-vcs --allow-dirty --allow-staged --profile --target-dir" local opt__generate_lockfile="$opt_common $opt_mani $opt_lock" @@ -69,10 +72,12 @@ _cargo() local opt__publish="$opt_common $opt_mani $opt_feat $opt_lock $opt_jobs --allow-dirty --dry-run --token --no-verify --index --registry --target --target-dir" local opt__read_manifest="$opt_help $opt_quiet $opt_verbose $opt_mani $opt_color $opt_lock --no-deps" local opt__run="$opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs --message-format --target --bin --example --release --target-dir --profile" + local opt__r="$opt__run" local opt__rustc="$opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_targets -L --crate-type --extern --message-format --profile --target --release --target-dir" local opt__rustdoc="$opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_targets --message-format --target --release --open --target-dir --profile" local opt__search="$opt_common $opt_lock --limit --index --registry" local opt__test="$opt_common $opt_pkg_spec $opt_feat $opt_mani $opt_lock $opt_jobs $opt_targets --message-format --doc --target --no-run --release --no-fail-fast --target-dir --profile" + local opt__t="$opt__test" local opt__tree="$opt_common $opt_pkg_spec $opt_feat $opt_mani $opt_lock --target -i --invert --prefix --no-dedupe --duplicates -d --charset -f --format -e --edges" local opt__uninstall="$opt_common $opt_lock $opt_pkg --bin --root" local opt__update="$opt_common $opt_mani $opt_lock $opt_pkg --aggressive --precise --dry-run"