Only add yadm commands to the completion list when applicable.

Before:
  yadm <TAB>  # Completes git and yadm commands.
  yadm -Y . <TAB>  # Completes yadm commands.
  yadm p<TAB> -u origin foo  # Completes yadm+git commands like p*.
  yadm push -u origin <TAB>  # Completes branch names and yadm commands.

After:
  yadm <TAB>  # Completes git and yadm commands.
  yadm -Y . <TAB>  # Completes yadm commands.
  yadm p<TAB> -u origin foo  # Completes yadm+git commands like p*.
  yadm push -u origin <TAB>  # Completes branch names.
This commit is contained in:
David Mandelberg 2019-01-04 21:44:49 -05:00 committed by Tim Byrne
parent 5d9e0a7133
commit bcf6531da6
No known key found for this signature in database
GPG Key ID: 14DB4FC2465A4B12
1 changed files with 13 additions and 1 deletions

View File

@ -74,7 +74,19 @@ if declare -F _git > /dev/null; then
__gitcompappend "$matching"
fi
if [ "$COMP_CWORD" == 1 ] || [[ "$antepenultimate" =~ ^- ]] ; then
# Find the index of where the sub-command argument should go.
local command_idx
for (( command_idx=1 ; command_idx < ${#COMP_WORDS[@]} ; command_idx++ )); do
local command_idx_arg="${COMP_WORDS[$command_idx]}"
if [[ " ${yadm_switches[*]} " = *" $command_idx_arg "* ]]; then
let command_idx++
elif [[ "$command_idx_arg" = -* ]]; then
:
else
break
fi
done
if [[ "$COMP_CWORD" = "$command_idx" ]]; then
local matching
matching=$(compgen -W "$(yadm introspect commands 2>/dev/null)" -- "$current")
__gitcompappend "$matching"