Fix completion after a command-line flag.

Before:
  yadm checkout -f <TAB>  # Completes filenames.
  yadm checkout --yadm-dir <TAB>  # Completes filenames.

After:
  yadm checkout -f <TAB>  # Completes branch names.
  yadm checkout --yadm-dir <TAB>  # Completes filenames.
This commit is contained in:
David Mandelberg 2019-01-04 21:17:34 -05:00 committed by Tim Byrne
parent 09a018ea5a
commit 60e0fbbf42
No known key found for this signature in database
GPG Key ID: 14DB4FC2465A4B12
1 changed files with 4 additions and 2 deletions

View File

@ -60,15 +60,17 @@ if declare -F _git > /dev/null; then
;;
esac
local yadm_switches=( $(yadm introspect switches 2>/dev/null) )
# this condition is so files are completed properly for --yadm-xxx options
if [[ ! "$penultimate" =~ ^- ]]; then
if [[ " ${yadm_switches[*]} " != *" $penultimate "* ]]; then
# TODO: somehow solve the problem with [--yadm-xxx option] being
# incompatible with what git expects, namely [--arg=option]
_git
fi
if [[ "$current" =~ ^- ]]; then
local matching
matching=$(compgen -W "$(yadm introspect switches 2>/dev/null)" -- "$current")
matching=$(compgen -W "${yadm_switches[*]}" -- "$current")
__gitcompappend "$matching"
fi