Skip to content

Commit caf7248

Browse files
committed
Auto merge of #9951 - relrelb:completion, r=alexcrichton
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 PR adds both bash and zsh completions for command shorthands. Fixes #9086.
2 parents d56b42c + 6a61ca5 commit caf7248

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/etc/_cargo

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ _cargo() {
7777
'*:args:_default'
7878
;;
7979

80-
build)
80+
build | b)
8181
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
8282
'--all-targets[equivalent to specifying --lib --bins --tests --benches --examples]' \
8383
"${command_scope_spec[@]}" \
@@ -86,7 +86,7 @@ _cargo() {
8686
'--build-plan[output the build plan in JSON]' \
8787
;;
8888

89-
check)
89+
check | c)
9090
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
9191
'--all-targets[equivalent to specifying --lib --bins --tests --benches --examples]' \
9292
"${command_scope_spec[@]}" \
@@ -101,7 +101,7 @@ _cargo() {
101101
'--doc[clean just the documentation directory]'
102102
;;
103103

104-
doc)
104+
doc | d)
105105
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
106106
'--no-deps[do not build docs for dependencies]' \
107107
'--document-private-items[include non-public items in the documentation]' \
@@ -220,7 +220,7 @@ _cargo() {
220220
_arguments -s -S $common $manifest
221221
;;
222222

223-
run)
223+
run | r)
224224
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
225225
'--example=[name of the bin target]:name:_cargo_example_names' \
226226
'--bin=[name of the bin target]:name' \
@@ -255,7 +255,7 @@ _cargo() {
255255
'*: :_guard "^-*" "query"'
256256
;;
257257

258-
test)
258+
test | t)
259259
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
260260
'--test=[test name]: :_cargo_test_names' \
261261
'--no-fail-fast[run all tests regardless of failure]' \

src/etc/cargo.bashcomp.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ _cargo()
5050
local opt___nocmd="$opt_common -V --version --list --explain"
5151
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"
5252
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"
53+
local opt__b="$opt__build"
5354
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"
55+
local opt__c="$opt__check"
5456
local opt__clean="$opt_common $opt_pkg $opt_mani $opt_lock --target --release --doc --target-dir --profile"
5557
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"
58+
local opt__d="$opt__doc"
5659
local opt__fetch="$opt_common $opt_mani $opt_lock --target"
5760
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"
5861
local opt__generate_lockfile="$opt_common $opt_mani $opt_lock"
@@ -69,10 +72,12 @@ _cargo()
6972
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"
7073
local opt__read_manifest="$opt_help $opt_quiet $opt_verbose $opt_mani $opt_color $opt_lock --no-deps"
7174
local opt__run="$opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs --message-format --target --bin --example --release --target-dir --profile"
75+
local opt__r="$opt__run"
7276
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"
7377
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"
7478
local opt__search="$opt_common $opt_lock --limit --index --registry"
7579
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"
80+
local opt__t="$opt__test"
7681
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"
7782
local opt__uninstall="$opt_common $opt_lock $opt_pkg --bin --root"
7883
local opt__update="$opt_common $opt_mani $opt_lock $opt_pkg --aggressive --precise --dry-run"

0 commit comments

Comments
 (0)