From 60e0fbbf427d78d102fadd83336b6af24e720dae Mon Sep 17 00:00:00 2001 From: David Mandelberg Date: Fri, 4 Jan 2019 21:17:34 -0500 Subject: [PATCH] Fix completion after a command-line flag. Before: yadm checkout -f # Completes filenames. yadm checkout --yadm-dir # Completes filenames. After: yadm checkout -f # Completes branch names. yadm checkout --yadm-dir # Completes filenames. --- completion/yadm.bash_completion | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/completion/yadm.bash_completion b/completion/yadm.bash_completion index 1091e55..34f199f 100644 --- a/completion/yadm.bash_completion +++ b/completion/yadm.bash_completion @@ -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