From 98c2550efcc30b1e47aa7501c62d93dfcf493f1e Mon Sep 17 00:00:00 2001 From: Thomas Nilefalk Date: Thu, 9 Feb 2023 15:35:04 +0100 Subject: [PATCH] [completion] Make completion work with zsh (somewhat...) --- tools/cgreen_completion.bash | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/cgreen_completion.bash b/tools/cgreen_completion.bash index 4114e502..299303f5 100644 --- a/tools/cgreen_completion.bash +++ b/tools/cgreen_completion.bash @@ -78,7 +78,7 @@ _cgreen_runner_completion() tests=() # Look for words in the command given so far - for word in ${COMP_WORDS[@]}; do + for word in ${COMP_WORDS[@]:1}; do # Matching loadable libraries? if compgen -G "$word*.$LIBEXT" > /dev/null; then # Add that pattern @@ -91,7 +91,7 @@ _cgreen_runner_completion() done # Remove all suggestions already used - for word in ${COMP_WORDS[@]}; do + for word in ${COMP_WORDS[@]:1}; do if [[ "$word" != "${COMP_WORDS[0]}" ]] ; then _removeFromOptions $word _removeFromLibraries $word @@ -100,12 +100,14 @@ _cgreen_runner_completion() done completion_word=${COMP_WORDS[$COMP_CWORD]} - COMPREPLY=($(compgen -W '$(printf "%s " ${options[@]} ${libraries[@]} ${tests[@]})' -- "$completion_word")) + expansions="${options[@]} ${libraries[@]} ${tests[@]}" + + COMPREPLY=($(compgen -W "$expansions" -- "$completion_word")) } _cgreen_debug_completion() { - local libraries tests + local options libraries tests options=("--debugger") libraries=() tests=() @@ -140,7 +142,9 @@ _cgreen_debug_completion() done completion_word=${COMP_WORDS[$COMP_CWORD]} - COMPREPLY=($(compgen -W '$(printf "%s " ${options[@]} ${libraries[@]} ${tests[@]})' -- "$completion_word")) + expansions="${options[@]} ${libraries[@]} ${tests[@]}" + + COMPREPLY=($(compgen -W "$expansions" -- "$completion_word")) } complete -o nosort -o dirnames -A directory -F _cgreen_runner_completion cgreen-runner