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:
parent
5d9e0a7133
commit
bcf6531da6
1 changed files with 13 additions and 1 deletions
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue