Skip to content

Commit 87566e1

Browse files
committed
feat(cli): complete --config and --color before command
Completing values for --config and --color was only supported in cases where those flags appear after the cargo subcommand. This commit adds support for completing their values before the cargo subcommand too.
1 parent 35c827a commit 87566e1

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/etc/cargo.bashcomp.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ _cargo()
1616
for (( cmd_i=1; cmd_i<$nwords; cmd_i++ ));
1717
do
1818
if [[ ! "${words[$cmd_i]}" =~ ^[+-] ]]; then
19+
if [[ $cmd_i -gt 0 ]]; then
20+
case "${words[(( $cmd_i - 1 ))]}" in
21+
--color|--config)
22+
continue
23+
;;
24+
esac
25+
fi
1926
cmd="${words[$cmd_i]}"
2027
break
2128
fi
@@ -109,8 +116,18 @@ _cargo()
109116
elif [[ "$cur" == +* ]]; then
110117
COMPREPLY=( $( compgen -W "$(_toolchains)" -- "$cur" ) )
111118
else
112-
_ensure_cargo_commands_cache_filled
113-
COMPREPLY=( $( compgen -W "$__cargo_commands_cache" -- "$cur" ) )
119+
case "${prev}" in
120+
--color)
121+
COMPREPLY=( $( compgen -W "$color" -- "$cur" ) )
122+
;;
123+
--config)
124+
_filedir
125+
;;
126+
*)
127+
_ensure_cargo_commands_cache_filled
128+
COMPREPLY=( $( compgen -W "$__cargo_commands_cache" -- "$cur" ) )
129+
;;
130+
esac
114131
fi
115132
else
116133
case "${prev}" in

0 commit comments

Comments
 (0)