Skip to content

Commit

Permalink
Add shell completion for shorthand commands
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
relrelb committed Oct 1, 2021
1 parent d56b42c commit 6a61ca5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/etc/_cargo
Original file line number Diff line number Diff line change
Expand Up @@ -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[@]}" \
Expand All @@ -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[@]}" \
Expand All @@ -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]' \
Expand Down Expand Up @@ -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' \
Expand Down Expand Up @@ -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]' \
Expand Down
5 changes: 5 additions & 0 deletions src/etc/cargo.bashcomp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 6a61ca5

Please sign in to comment.