Skip to content

Commit

Permalink
CA-399956 - xe autocompletion: Fix autocompletion for words with give…
Browse files Browse the repository at this point in the history
…n prefix (#6031)

For unresolved reasons, `compgen -W` would not work as intended
occasionally:

`xe host-param-get uuid=xxx param-na<TAB>`

would complete to:

`xe host-param-get uuid=xxx param-name=`

but typing:

`xe host-param-get uuid=xxx param-name=so<TAB>`

would not complete it to:

`xe host-param-get uuid=xxx param-name=software-version`

It's unlikely to be a bug in Bash since I couldn't find anything in the
changelog and upgrading the package did not fix it; nor could I
reproduce it in
a different program with the same inputs - it is likely that something
in the
environment breaks compgen. Switch to pure Bash string processing
instead.
  • Loading branch information
psafont authored Oct 2, 2024
2 parents 382a63b + 6d3edbb commit 9d4f2ab
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ocaml/xe-cli/bash-completion
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,12 @@ __preprocess_suggestions()
wordlist=$( echo "$1" | \
sed -re 's/(^|[^\])((\\\\)*),,*/\1\2\n/g' -e 's/\\,/,/g' -e 's/\\\\/\\/g' | \
sed -e 's/ *$//')
compgen -W "$wordlist" "$prefix"
local IFS=$'\n'
for word in $wordlist; do
if [[ "$word" =~ ^$prefix.* ]]; then
echo "$word"
fi
done
}

# set_completions suggestions current_prefix description_cmd
Expand Down

0 comments on commit 9d4f2ab

Please sign in to comment.