From 6d3edbbb2b045eee48097374c16125d6ebb571c6 Mon Sep 17 00:00:00 2001 From: Andrii Sultanov Date: Wed, 2 Oct 2024 08:46:16 +0100 Subject: [PATCH] CA-399956 - xe autocompletion: Fix autocompletion for words with given prefix For unresolved reasons, 'compgen -W' would not work as intended occasionally: 'xe host-param-get uuid=xxx param-na' would complete to: 'xe host-param-get uuid=xxx param-name=' but typing: 'xe host-param-get uuid=xxx param-name=so' 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. Signed-off-by: Andrii Sultanov --- ocaml/xe-cli/bash-completion | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ocaml/xe-cli/bash-completion b/ocaml/xe-cli/bash-completion index 98df8be24fb..b4ba6127138 100644 --- a/ocaml/xe-cli/bash-completion +++ b/ocaml/xe-cli/bash-completion @@ -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