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

feat(cli): forward bash completions of third party subcommands #15247

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
11 changes: 9 additions & 2 deletions src/etc/cargo.bashcomp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,15 @@ _cargo()
local opt_var=opt__${cmd//-/_}
fi
if [[ -z "${!opt_var-}" ]]; then
# Fallback to filename completion.
_filedir
# Forward to subcommands completion if bash-completion >= 2.12 is available
if [[ $BASH_COMPLETION_VERSINFO && (${BASH_COMPLETION_VERSINFO[0]} -gt 2 || (${BASH_COMPLETION_VERSINFO[0]} -eq 2 && ${BASH_COMPLETION_VERSINFO[1]} -ge 12)) ]]; then
COMP_WORDS[cmd_i]="cargo-$cmd"
_comp_command_offset "$cmd_i"
COMP_WORDS[cmd_i]="$cmd"
else
# Fallback to filename completion.
_filedir
fi
else
COMPREPLY=( $( compgen -W "${!opt_var}" -- "$cur" ) )
fi
Expand Down