Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve startup time of bash completion. #10365

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/etc/cargo.bashcomp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ _cargo()
elif [[ "$cur" == +* ]]; then
COMPREPLY=( $( compgen -W "$(_toolchains)" -- "$cur" ) )
else
COMPREPLY=( $( compgen -W "$__cargo_commands" -- "$cur" ) )
_ensure_cargo_commands_cache_filled
COMPREPLY=( $( compgen -W "$__cargo_commands_cache" -- "$cur" ) )
fi
else
case "${prev}" in
Expand Down Expand Up @@ -140,7 +141,8 @@ _cargo()
_filedir -d
;;
help)
COMPREPLY=( $( compgen -W "$__cargo_commands" -- "$cur" ) )
_ensure_cargo_commands_cache_filled
COMPREPLY=( $( compgen -W "$__cargo_commands_cache" -- "$cur" ) )
;;
*)
if [[ "$cmd" == "report" && "$prev" == future-incompat* ]]; then
Expand All @@ -164,7 +166,12 @@ _cargo()
} &&
complete -F _cargo cargo

__cargo_commands=$(cargo --list 2>/dev/null | awk 'NR>1 {print $1}')
__cargo_commands_cache=
_ensure_cargo_commands_cache_filled(){
if [[ -z $__cargo_commands_cache ]]; then
__cargo_commands_cache="$(cargo --list 2>/dev/null | awk 'NR>1 {print $1}')"
fi
}

_locate_manifest(){
cargo locate-project --message-format plain 2>/dev/null
Expand Down