@@ -8,65 +8,84 @@ _cargo()
8
8
9
9
# Skip past - and + options to find the command.
10
10
local nwords=${# words[@]}
11
- local cmd_i cmd
11
+ local cmd_i cmd dd_i
12
12
for (( cmd_i= 1 ; cmd_i< $nwords ; cmd_i++ )) ;
13
13
do
14
14
if [[ ! " ${words[$cmd_i]} " =~ ^[+-] ]]; then
15
15
cmd=" ${words[$cmd_i]} "
16
16
break
17
17
fi
18
18
done
19
+ # Find the location of the -- separator.
20
+ for (( dd_i= 1 ; dd_i< $nwords - 1 ; dd_i++ )) ;
21
+ do
22
+ if [[ " ${words[$dd_i]} " = " --" ]]; then
23
+ break
24
+ fi
25
+ done
19
26
20
- local vcs=' git hg none'
27
+ local vcs=' git hg none pijul fossil '
21
28
local color=' auto always never'
22
- local msg_format=' human json'
29
+ local msg_format=' human json short '
23
30
24
31
local opt_help=' -h --help'
25
32
local opt_verbose=' -v --verbose'
26
33
local opt_quiet=' -q --quiet'
27
34
local opt_color=' --color'
28
35
local opt_common=" $opt_help $opt_verbose $opt_quiet $opt_color "
36
+ local opt_pkg_spec=' -p --package --all --exclude'
29
37
local opt_pkg=' -p --package'
30
38
local opt_feat=' --features --all-features --no-default-features'
31
39
local opt_mani=' --manifest-path'
32
40
local opt_jobs=' -j --jobs'
33
41
local opt_force=' -f --force'
34
42
local opt_test=' --test --bench'
35
43
local opt_lock=' --frozen --locked'
44
+ local opt_targets=" --lib --bin --bins --example --examples --test --tests --bench --benches --all-targets"
36
45
37
- local opt___nocmd=" $opt_common -V --version --list"
38
- local opt__bench=" $opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test --message-format --target --lib --bin --example --no-run "
39
- local opt__build=" $opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test --message-format --target --lib --bin --example --release "
40
- local opt__check=" $opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test --message-format --target --lib --bin --example --release "
41
- local opt__clean=" $opt_common $opt_pkg $opt_mani $opt_lock --target --release"
42
- local opt__doc=" $opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs --message-format --bin --lib --target --open --no-deps --release"
46
+ local opt___nocmd=" $opt_common -V --version --list --explain "
47
+ local opt__bench=" $opt_common $opt_pkg_spec $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test $opt_targets --message-format --target --no-run --no-fail-fast --target-dir "
48
+ local opt__build=" $opt_common $opt_pkg_spec $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test $opt_targets --message-format --target --release --target-dir "
49
+ local opt__check=" $opt_common $opt_pkg_spec $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test $opt_targets --message-format --target --release --profile --target-dir "
50
+ local opt__clean=" $opt_common $opt_pkg $opt_mani $opt_lock --target --release --doc --target-dir "
51
+ 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 "
43
52
local opt__fetch=" $opt_common $opt_mani $opt_lock "
53
+ local opt__fix=" $opt_common $opt_pkg_spec $opt_feat $opt_mani $opt_jobs $opt_targets $opt_lock --release --target --message-format --prepare-for --broken-code --edition --edition-idioms --allow-no-vcs --allow-dirty --allow-staged --profile --target-dir"
44
54
local opt__generate_lockfile=" ${opt__fetch} "
45
55
local opt__git_checkout=" $opt_common $opt_lock --reference --url"
46
56
local opt__help=" $opt_help "
47
- local opt__init=" $opt_common $opt_lock --bin --lib --name --vcs"
48
- local opt__install=" $opt_common $opt_feat $opt_jobs $opt_lock $opt_force --bin --branch --debug --example --git --list --path --rev --root --tag --vers "
57
+ local opt__init=" $opt_common $opt_lock --bin --lib --name --vcs --edition --registry "
58
+ local opt__install=" $opt_common $opt_feat $opt_jobs $opt_lock $opt_force --bin --bins -- branch --debug --example --examples -- git --list --path --rev --root --tag --version --registry --target "
49
59
local opt__locate_project=" $opt_mani -h --help"
50
- local opt__login=" $opt_common $opt_lock --host"
51
- local opt__metadata=" $opt_common $opt_feat $opt_mani $opt_lock --format-version --no-deps"
52
- local opt__new=" $opt_common $opt_lock --vcs --bin --lib --name"
53
- local opt__owner=" $opt_common $opt_lock -a --add -r --remove -l --list --index --token"
54
- local opt__package=" $opt_common $opt_mani $opt_lock $opt_jobs --allow-dirty -l --list --no-verify --no-metadata"
60
+ local opt__login=" $opt_common $opt_lock --host --registry "
61
+ local opt__metadata=" $opt_common $opt_feat $opt_mani $opt_lock --format-version=1 --no-deps"
62
+ local opt__new=" $opt_common $opt_lock --vcs --bin --lib --name --edition --registry "
63
+ local opt__owner=" $opt_common $opt_lock -a --add -r --remove -l --list --index --token --registry "
64
+ local opt__package=" $opt_common $opt_mani $opt_feat $ opt_lock $opt_jobs --allow-dirty -l --list --no-verify --no-metadata --target --target-dir "
55
65
local opt__pkgid=" ${opt__fetch} $opt_pkg "
56
- local opt__publish=" $opt_common $opt_mani $opt_lock $opt_jobs --allow-dirty --dry-run --host --token --no-verify"
57
- local opt__read_manifest=" $opt_help $opt_verbose $opt_mani $opt_color --no-deps "
58
- local opt__run=" $opt_common $opt_feat $opt_mani $opt_lock $opt_jobs --message-format --target --bin --example --release"
59
- local opt__rustc=" $opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test --message-format --profile --target --lib --bin --example --release "
60
- local opt__rustdoc=" $opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test --message-format --target --lib --bin --example --release --open "
61
- local opt__search=" $opt_common $opt_lock --host --limit"
62
- local opt__test=" $opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test --message-format --all -- doc --target --lib --bin --example -- no-run --release --no-fail-fast"
63
- local opt__uninstall=" $opt_common $opt_lock --bin --root"
64
- local opt__update=" $opt_common $opt_pkg $opt_mani $opt_lock --aggressive --precise"
66
+ local opt__publish=" $opt_common $opt_mani $opt_feat $ opt_lock $opt_jobs --allow-dirty --dry-run --host --token --no-verify --index --registry --target --target-dir "
67
+ local opt__read_manifest=" $opt_help $opt_quiet $ opt_verbose $opt_mani $opt_color "
68
+ local opt__run=" $opt_common $opt_pkg $ opt_feat $opt_mani $opt_lock $opt_jobs --message-format --target --bin --example --release --target-dir "
69
+ local opt__rustc=" $opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test $opt_targets --message-format --profile --target --release --target-dir "
70
+ local opt__rustdoc=" $opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test $opt_targets --message-format --target --release --open --target-dir "
71
+ local opt__search=" $opt_common $opt_lock --host --limit --index --limit --registry "
72
+ local opt__test=" $opt_common $opt_pkg_spec $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test $opt_targets --message-format --doc --target --no-run --release --no-fail-fast --target-dir "
73
+ local opt__uninstall=" $opt_common $opt_lock $opt_pkg_spec --bin --root"
74
+ local opt__update=" $opt_common $opt_pkg_spec $opt_mani $opt_lock --aggressive --precise --dry-run "
65
75
local opt__verify_project=" ${opt__fetch} "
66
76
local opt__version=" $opt_help $opt_verbose $opt_color "
67
- local opt__yank=" $opt_common $opt_lock --vers --undo --index --token"
77
+ local opt__yank=" $opt_common $opt_lock --vers --undo --index --token --registry"
78
+ local opt__libtest=" --help --include-ignored --ignored --test --bench --list --logfile --nocapture --test-threads --skip -q --quiet --exact --color --format"
68
79
69
- if [[ $cmd_i -ge $nwords -1 ]]; then
80
+ if [[ $cword -gt $dd_i ]]; then
81
+ # Completion after -- separator.
82
+ if [[ " ${cmd} " = @ (test| bench) ]]; then
83
+ COMPREPLY=( $( compgen -W " ${opt__libtest} " -- " $cur " ) )
84
+ else
85
+ # Fallback to filename completion, useful with `cargo run`.
86
+ _filedir
87
+ fi
88
+ elif [[ $cword -le $cmd_i ]]; then
70
89
# Completion before or at the command.
71
90
if [[ " $cur " == -* ]]; then
72
91
COMPREPLY=( $( compgen -W " ${opt___nocmd} " -- " $cur " ) )
@@ -104,12 +123,20 @@ _cargo()
104
123
--target)
105
124
COMPREPLY=( $( compgen -W " $( _get_targets) " -- " $cur " ) )
106
125
;;
126
+ --target-dir)
127
+ _filedir -d
128
+ ;;
107
129
help)
108
130
COMPREPLY=( $( compgen -W " $__cargo_commands " -- " $cur " ) )
109
131
;;
110
132
* )
111
133
local opt_var=opt__${cmd// -/ _}
112
- COMPREPLY=( $( compgen -W " ${! opt_var} " -- " $cur " ) )
134
+ if [[ -z " ${! opt_var} " ]]; then
135
+ # Fallback to filename completion.
136
+ _filedir
137
+ else
138
+ COMPREPLY=( $( compgen -W " ${! opt_var} " -- " $cur " ) )
139
+ fi
113
140
;;
114
141
esac
115
142
fi
@@ -197,31 +224,15 @@ _get_examples(){
197
224
}
198
225
199
226
_get_targets (){
200
- local CURRENT_PATH
201
- if [ ` uname -o` == " Cygwin" -a -f " $PWD " /Cargo.toml ]; then
202
- CURRENT_PATH=$PWD
203
- else
204
- CURRENT_PATH=$( _locate_manifest)
205
- fi
206
- if [[ -z " $CURRENT_PATH " ]]; then
207
- return 1
208
- fi
209
- local TARGETS=()
210
- local FIND_PATHS=( " /" )
211
- local FIND_PATH LINES LINE
212
- while [[ " $CURRENT_PATH " != " /" ]]; do
213
- FIND_PATHS+=( " $CURRENT_PATH " )
214
- CURRENT_PATH=$( dirname $CURRENT_PATH )
215
- done
216
- for FIND_PATH in ${FIND_PATHS[@]} ; do
217
- if [[ -f " $FIND_PATH " /.cargo/config ]]; then
218
- LINES=( ` grep " $FIND_PATH " /.cargo/config -e " ^\[target\." ` )
219
- for LINE in ${LINES[@]} ; do
220
- TARGETS+=(` sed ' s/^\[target\.\(.*\)\]$/\1/' <<< $LINE ` )
221
- done
227
+ local result=()
228
+ local targets=$( rustup target list)
229
+ while read line
230
+ do
231
+ if [[ " $line " =~ default| installed ]]; then
232
+ result+=(" ${line%% * } " )
222
233
fi
223
- done
224
- echo " ${TARGETS [@]} "
234
+ done <<< " $targets "
235
+ echo " ${result [@]} "
225
236
}
226
237
227
238
_toolchains (){
0 commit comments