diff --git a/src/test/java/picocli/AutoCompleteTest.java b/src/test/java/picocli/AutoCompleteTest.java index 69167a549..b3a1d9924 100644 --- a/src/test/java/picocli/AutoCompleteTest.java +++ b/src/test/java/picocli/AutoCompleteTest.java @@ -756,6 +756,41 @@ private String expectedCompletionScriptForAutoCompleteApp() { " echo \"$result\"\n" + "}\n" + "\n" + + "# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.\n" + + "#\n" + + "# compReplyArray takes a single parameter: the array of options to be displayed\n" + + "#\n" + + "# The output is echoed to std_out, one option per line.\n" + + "#\n" + + "# Example usage:\n" + + "# local options=(\"foo\", \"bar\", \"baz\")\n" + + "# local IFS=$'\\n'\n" + + "# COMPREPLY=$(compReplyArray \"${options[@]}\")\n" + + "function compReplyArray() {\n" + + " declare -a options\n" + + " options=(\"$@\")\n" + + " local curr_word=${COMP_WORDS[COMP_CWORD]}\n" + + " local i\n" + + " local quoted\n" + + " local optionList=()\n" + + "\n" + + " for (( i=0; i<${#options[@]}; i++ )); do\n" + + " # Double escape, since we want escaped values, but compgen -W expands the argument\n" + + " printf -v quoted %%q \"${options[i]}\"\n" + + " quoted=\\'${quoted//\\'/\\'\\\\\\'\\'}\\'\n" + + "\n" + + " optionList[i]=$quoted\n" + + " done\n" + + "\n" + + " # We also have to add another round of escaping to $curr_word.\n" + + " curr_word=${curr_word//\\\\/\\\\\\\\}\n" + + " curr_word=${curr_word//\\'/\\\\\\'}\n" + + "\n" + + " # Actually generate completions.\n" + + " local IFS=$'\\n'\n" + + " echo -e \"$(compgen -W \"${optionList[*]}\" -- \"$curr_word\")\"\n" + + "}\n" + + "\n" + "# Bash completion entry point function.\n" + "# _complete_picocli.AutoComplete finds which commands and subcommands have been specified\n" + "# on the command line and delegates to the appropriate function\n" + @@ -974,6 +1009,41 @@ private String expectedCompletionScriptForNonDefault() { " echo \"$result\"\n" + "}\n" + "\n" + + "# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.\n" + + "#\n" + + "# compReplyArray takes a single parameter: the array of options to be displayed\n" + + "#\n" + + "# The output is echoed to std_out, one option per line.\n" + + "#\n" + + "# Example usage:\n" + + "# local options=(\"foo\", \"bar\", \"baz\")\n" + + "# local IFS=$'\\n'\n" + + "# COMPREPLY=$(compReplyArray \"${options[@]}\")\n" + + "function compReplyArray() {\n" + + " declare -a options\n" + + " options=(\"$@\")\n" + + " local curr_word=${COMP_WORDS[COMP_CWORD]}\n" + + " local i\n" + + " local quoted\n" + + " local optionList=()\n" + + "\n" + + " for (( i=0; i<${#options[@]}; i++ )); do\n" + + " # Double escape, since we want escaped values, but compgen -W expands the argument\n" + + " printf -v quoted %%q \"${options[i]}\"\n" + + " quoted=\\'${quoted//\\'/\\'\\\\\\'\\'}\\'\n" + + "\n" + + " optionList[i]=$quoted\n" + + " done\n" + + "\n" + + " # We also have to add another round of escaping to $curr_word.\n" + + " curr_word=${curr_word//\\\\/\\\\\\\\}\n" + + " curr_word=${curr_word//\\'/\\\\\\'}\n" + + "\n" + + " # Actually generate completions.\n" + + " local IFS=$'\\n'\n" + + " echo -e \"$(compgen -W \"${optionList[*]}\" -- \"$curr_word\")\"\n" + + "}\n" + + "\n" + "# Bash completion entry point function.\n" + "# _complete_nondefault finds which commands and subcommands have been specified\n" + "# on the command line and delegates to the appropriate function\n" + @@ -1540,6 +1610,41 @@ private String getCompletionScriptText(String cmdName) { " echo \"$result\"\n" + "}\n" + "\n" + + "# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.\n" + + "#\n" + + "# compReplyArray takes a single parameter: the array of options to be displayed\n" + + "#\n" + + "# The output is echoed to std_out, one option per line.\n" + + "#\n" + + "# Example usage:\n" + + "# local options=(\"foo\", \"bar\", \"baz\")\n" + + "# local IFS=$'\\n'\n" + + "# COMPREPLY=$(compReplyArray \"${options[@]}\")\n" + + "function compReplyArray() {\n" + + " declare -a options\n" + + " options=(\"$@\")\n" + + " local curr_word=${COMP_WORDS[COMP_CWORD]}\n" + + " local i\n" + + " local quoted\n" + + " local optionList=()\n" + + "\n" + + " for (( i=0; i<${#options[@]}; i++ )); do\n" + + " # Double escape, since we want escaped values, but compgen -W expands the argument\n" + + " printf -v quoted %%q \"${options[i]}\"\n" + + " quoted=\\'${quoted//\\'/\\'\\\\\\'\\'}\\'\n" + + "\n" + + " optionList[i]=$quoted\n" + + " done\n" + + "\n" + + " # We also have to add another round of escaping to $curr_word.\n" + + " curr_word=${curr_word//\\\\/\\\\\\\\}\n" + + " curr_word=${curr_word//\\'/\\\\\\'}\n" + + "\n" + + " # Actually generate completions.\n" + + " local IFS=$'\\n'\n" + + " echo -e \"$(compgen -W \"${optionList[*]}\" -- \"$curr_word\")\"\n" + + "}\n" + + "\n" + "# Bash completion entry point function.\n" + "# _complete_%1$s finds which commands and subcommands have been specified\n" + "# on the command line and delegates to the appropriate function\n" + @@ -1752,6 +1857,41 @@ private String getCompletionScriptTextWithHidden(String commandName) { " echo \"$result\"\n" + "}\n" + "\n" + + "# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.\n" + + "#\n" + + "# compReplyArray takes a single parameter: the array of options to be displayed\n" + + "#\n" + + "# The output is echoed to std_out, one option per line.\n" + + "#\n" + + "# Example usage:\n" + + "# local options=(\"foo\", \"bar\", \"baz\")\n" + + "# local IFS=$'\\n'\n" + + "# COMPREPLY=$(compReplyArray \"${options[@]}\")\n" + + "function compReplyArray() {\n" + + " declare -a options\n" + + " options=(\"$@\")\n" + + " local curr_word=${COMP_WORDS[COMP_CWORD]}\n" + + " local i\n" + + " local quoted\n" + + " local optionList=()\n" + + "\n" + + " for (( i=0; i<${#options[@]}; i++ )); do\n" + + " # Double escape, since we want escaped values, but compgen -W expands the argument\n" + + " printf -v quoted %%q \"${options[i]}\"\n" + + " quoted=\\'${quoted//\\'/\\'\\\\\\'\\'}\\'\n" + + "\n" + + " optionList[i]=$quoted\n" + + " done\n" + + "\n" + + " # We also have to add another round of escaping to $curr_word.\n" + + " curr_word=${curr_word//\\\\/\\\\\\\\}\n" + + " curr_word=${curr_word//\\'/\\\\\\'}\n" + + "\n" + + " # Actually generate completions.\n" + + " local IFS=$'\\n'\n" + + " echo -e \"$(compgen -W \"${optionList[*]}\" -- \"$curr_word\")\"\n" + + "}\n" + + "\n" + "# Bash completion entry point function.\n" + "# _complete_%1$s finds which commands and subcommands have been specified\n" + "# on the command line and delegates to the appropriate function\n" + diff --git a/src/test/resources/bashify_completion.bash b/src/test/resources/bashify_completion.bash index 012582f24..5dfebaacf 100644 --- a/src/test/resources/bashify_completion.bash +++ b/src/test/resources/bashify_completion.bash @@ -113,6 +113,41 @@ function currentPositionalIndex() { echo "$result" } +# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped. +# +# compReplyArray takes a single parameter: the array of options to be displayed +# +# The output is echoed to std_out, one option per line. +# +# Example usage: +# local options=("foo", "bar", "baz") +# local IFS=$'\n' +# COMPREPLY=$(compReplyArray "${options[@]}") +function compReplyArray() { + declare -a options + options=("$@") + local curr_word=${COMP_WORDS[COMP_CWORD]} + local i + local quoted + local optionList=() + + for (( i=0; i<${#options[@]}; i++ )); do + # Double escape, since we want escaped values, but compgen -W expands the argument + printf -v quoted %%q "${options[i]}" + quoted=\'${quoted//\'/\'\\\'\'}\' + + optionList[i]=$quoted + done + + # We also have to add another round of escaping to $curr_word. + curr_word=${curr_word//\\/\\\\} + curr_word=${curr_word//\'/\\\'} + + # Actually generate completions. + local IFS=$'\n' + echo -e "$(compgen -W "${optionList[*]}" -- "$curr_word")" +} + # Bash completion entry point function. # _complete_bashify finds which commands and subcommands have been specified # on the command line and delegates to the appropriate function @@ -143,7 +178,7 @@ function _picocli_bashify() { case ${prev_word} in -x) local IFS=$'\n' - COMPREPLY=( $( compgen -W "${_AB_C_option_args[*]}" -- "${curr_word}" ) ) + COMPREPLY=( $( compReplyArray "${_AB_C_option_args[@]}" ) ) return $? ;; esac diff --git a/src/test/resources/basic.bash b/src/test/resources/basic.bash index 699453402..42e33a93d 100644 --- a/src/test/resources/basic.bash +++ b/src/test/resources/basic.bash @@ -113,6 +113,41 @@ function currentPositionalIndex() { echo "$result" } +# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped. +# +# compReplyArray takes a single parameter: the array of options to be displayed +# +# The output is echoed to std_out, one option per line. +# +# Example usage: +# local options=("foo", "bar", "baz") +# local IFS=$'\n' +# COMPREPLY=$(compReplyArray "${options[@]}") +function compReplyArray() { + declare -a options + options=("$@") + local curr_word=${COMP_WORDS[COMP_CWORD]} + local i + local quoted + local optionList=() + + for (( i=0; i<${#options[@]}; i++ )); do + # Double escape, since we want escaped values, but compgen -W expands the argument + printf -v quoted %%q "${options[i]}" + quoted=\'${quoted//\'/\'\\\'\'}\' + + optionList[i]=$quoted + done + + # We also have to add another round of escaping to $curr_word. + curr_word=${curr_word//\\/\\\\} + curr_word=${curr_word//\'/\\\'} + + # Actually generate completions. + local IFS=$'\n' + echo -e "$(compgen -W "${optionList[*]}" -- "$curr_word")" +} + # Bash completion entry point function. # _complete_basicExample finds which commands and subcommands have been specified # on the command line and delegates to the appropriate function @@ -143,7 +178,7 @@ function _picocli_basicExample() { case ${prev_word} in -u|--timeUnit) local IFS=$'\n' - COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) + COMPREPLY=( $( compReplyArray "${timeUnit_option_args[@]}" ) ) return $? ;; -t|--timeout) diff --git a/src/test/resources/hyphenated_completion.bash b/src/test/resources/hyphenated_completion.bash index 59f7c20e6..0ebcdbe8c 100644 --- a/src/test/resources/hyphenated_completion.bash +++ b/src/test/resources/hyphenated_completion.bash @@ -113,6 +113,41 @@ function currentPositionalIndex() { echo "$result" } +# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped. +# +# compReplyArray takes a single parameter: the array of options to be displayed +# +# The output is echoed to std_out, one option per line. +# +# Example usage: +# local options=("foo", "bar", "baz") +# local IFS=$'\n' +# COMPREPLY=$(compReplyArray "${options[@]}") +function compReplyArray() { + declare -a options + options=("$@") + local curr_word=${COMP_WORDS[COMP_CWORD]} + local i + local quoted + local optionList=() + + for (( i=0; i<${#options[@]}; i++ )); do + # Double escape, since we want escaped values, but compgen -W expands the argument + printf -v quoted %%q "${options[i]}" + quoted=\'${quoted//\'/\'\\\'\'}\' + + optionList[i]=$quoted + done + + # We also have to add another round of escaping to $curr_word. + curr_word=${curr_word//\\/\\\\} + curr_word=${curr_word//\'/\\\'} + + # Actually generate completions. + local IFS=$'\n' + echo -e "$(compgen -W "${optionList[*]}" -- "$curr_word")" +} + # Bash completion entry point function. # _complete_rcmd finds which commands and subcommands have been specified # on the command line and delegates to the appropriate function diff --git a/src/test/resources/picocompletion-demo-help_completion.bash b/src/test/resources/picocompletion-demo-help_completion.bash index f1879b199..94512134c 100644 --- a/src/test/resources/picocompletion-demo-help_completion.bash +++ b/src/test/resources/picocompletion-demo-help_completion.bash @@ -113,6 +113,41 @@ function currentPositionalIndex() { echo "$result" } +# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped. +# +# compReplyArray takes a single parameter: the array of options to be displayed +# +# The output is echoed to std_out, one option per line. +# +# Example usage: +# local options=("foo", "bar", "baz") +# local IFS=$'\n' +# COMPREPLY=$(compReplyArray "${options[@]}") +function compReplyArray() { + declare -a options + options=("$@") + local curr_word=${COMP_WORDS[COMP_CWORD]} + local i + local quoted + local optionList=() + + for (( i=0; i<${#options[@]}; i++ )); do + # Double escape, since we want escaped values, but compgen -W expands the argument + printf -v quoted %%q "${options[i]}" + quoted=\'${quoted//\'/\'\\\'\'}\' + + optionList[i]=$quoted + done + + # We also have to add another round of escaping to $curr_word. + curr_word=${curr_word//\\/\\\\} + curr_word=${curr_word//\'/\\\'} + + # Actually generate completions. + local IFS=$'\n' + echo -e "$(compgen -W "${optionList[*]}" -- "$curr_word")" +} + # Bash completion entry point function. # _complete_picocompletion-demo-help finds which commands and subcommands have been specified # on the command line and delegates to the appropriate function @@ -218,7 +253,7 @@ function _picocli_picocompletion-demo-help_sub1() { ;; --candidates) local IFS=$'\n' - COMPREPLY=( $( compgen -W "${str2_option_args[*]}" -- "${curr_word}" ) ) + COMPREPLY=( $( compReplyArray "${str2_option_args[@]}" ) ) return $? ;; esac @@ -254,7 +289,7 @@ function _picocli_picocompletion-demo-help_sub1alias() { ;; --candidates) local IFS=$'\n' - COMPREPLY=( $( compgen -W "${str2_option_args[*]}" -- "${curr_word}" ) ) + COMPREPLY=( $( compReplyArray "${str2_option_args[@]}" ) ) return $? ;; esac @@ -300,8 +335,7 @@ function _picocli_picocompletion-demo-help_sub2() { local currIndex currIndex=$(currentPositionalIndex "sub2" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${possibilities_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${possibilities_pos_param_args[@]}" ) fi local IFS=$'\n' COMPREPLY=( $(compgen -W "${commands// /$'\n'}${IFS}${positionals}" -- "${curr_word}") ) @@ -340,8 +374,7 @@ function _picocli_picocompletion-demo-help_sub2alias() { local currIndex currIndex=$(currentPositionalIndex "sub2-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${possibilities_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${possibilities_pos_param_args[@]}" ) fi local IFS=$'\n' COMPREPLY=( $(compgen -W "${commands// /$'\n'}${IFS}${positionals}" -- "${curr_word}") ) @@ -440,7 +473,7 @@ function _picocli_picocompletion-demo-help_sub2_subsub2() { case ${prev_word} in -u|--timeUnit) local IFS=$'\n' - COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) + COMPREPLY=( $( compReplyArray "${timeUnit_option_args[@]}" ) ) return $? ;; -t|--timeout) @@ -456,8 +489,7 @@ function _picocli_picocompletion-demo-help_sub2_subsub2() { local currIndex currIndex=$(currentPositionalIndex "subsub2" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${str2_pos_param_args[@]}" ) fi local IFS=$'\n' COMPREPLY=( $(compgen -W "${commands// /$'\n'}${IFS}${positionals}" -- "${curr_word}") ) @@ -480,7 +512,7 @@ function _picocli_picocompletion-demo-help_sub2_sub2child2alias() { case ${prev_word} in -u|--timeUnit) local IFS=$'\n' - COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) + COMPREPLY=( $( compReplyArray "${timeUnit_option_args[@]}" ) ) return $? ;; -t|--timeout) @@ -496,8 +528,7 @@ function _picocli_picocompletion-demo-help_sub2_sub2child2alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child2-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${str2_pos_param_args[@]}" ) fi local IFS=$'\n' COMPREPLY=( $(compgen -W "${commands// /$'\n'}${IFS}${positionals}" -- "${curr_word}") ) @@ -521,8 +552,7 @@ function _picocli_picocompletion-demo-help_sub2_subsub3() { local currIndex currIndex=$(currentPositionalIndex "subsub3" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${cands_pos_param_args[@]}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames @@ -553,8 +583,7 @@ function _picocli_picocompletion-demo-help_sub2_sub2child3alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child3-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${cands_pos_param_args[@]}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames @@ -642,7 +671,7 @@ function _picocli_picocompletion-demo-help_sub2alias_subsub2() { case ${prev_word} in -u|--timeUnit) local IFS=$'\n' - COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) + COMPREPLY=( $( compReplyArray "${timeUnit_option_args[@]}" ) ) return $? ;; -t|--timeout) @@ -658,8 +687,7 @@ function _picocli_picocompletion-demo-help_sub2alias_subsub2() { local currIndex currIndex=$(currentPositionalIndex "subsub2" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${str2_pos_param_args[@]}" ) fi local IFS=$'\n' COMPREPLY=( $(compgen -W "${commands// /$'\n'}${IFS}${positionals}" -- "${curr_word}") ) @@ -682,7 +710,7 @@ function _picocli_picocompletion-demo-help_sub2alias_sub2child2alias() { case ${prev_word} in -u|--timeUnit) local IFS=$'\n' - COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) + COMPREPLY=( $( compReplyArray "${timeUnit_option_args[@]}" ) ) return $? ;; -t|--timeout) @@ -698,8 +726,7 @@ function _picocli_picocompletion-demo-help_sub2alias_sub2child2alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child2-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${str2_pos_param_args[@]}" ) fi local IFS=$'\n' COMPREPLY=( $(compgen -W "${commands// /$'\n'}${IFS}${positionals}" -- "${curr_word}") ) @@ -723,8 +750,7 @@ function _picocli_picocompletion-demo-help_sub2alias_subsub3() { local currIndex currIndex=$(currentPositionalIndex "subsub3" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${cands_pos_param_args[@]}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames @@ -755,8 +781,7 @@ function _picocli_picocompletion-demo-help_sub2alias_sub2child3alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child3-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${cands_pos_param_args[@]}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames diff --git a/src/test/resources/picocompletion-demo_completion.bash b/src/test/resources/picocompletion-demo_completion.bash index 6626b1e45..b773350be 100644 --- a/src/test/resources/picocompletion-demo_completion.bash +++ b/src/test/resources/picocompletion-demo_completion.bash @@ -113,6 +113,41 @@ function currentPositionalIndex() { echo "$result" } +# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped. +# +# compReplyArray takes a single parameter: the array of options to be displayed +# +# The output is echoed to std_out, one option per line. +# +# Example usage: +# local options=("foo", "bar", "baz") +# local IFS=$'\n' +# COMPREPLY=$(compReplyArray "${options[@]}") +function compReplyArray() { + declare -a options + options=("$@") + local curr_word=${COMP_WORDS[COMP_CWORD]} + local i + local quoted + local optionList=() + + for (( i=0; i<${#options[@]}; i++ )); do + # Double escape, since we want escaped values, but compgen -W expands the argument + printf -v quoted %%q "${options[i]}" + quoted=\'${quoted//\'/\'\\\'\'}\' + + optionList[i]=$quoted + done + + # We also have to add another round of escaping to $curr_word. + curr_word=${curr_word//\\/\\\\} + curr_word=${curr_word//\'/\\\'} + + # Actually generate completions. + local IFS=$'\n' + echo -e "$(compgen -W "${optionList[*]}" -- "$curr_word")" +} + # Bash completion entry point function. # _complete_picocompletion-demo finds which commands and subcommands have been specified # on the command line and delegates to the appropriate function @@ -215,7 +250,7 @@ function _picocli_picocompletion-demo_sub1() { ;; --candidates) local IFS=$'\n' - COMPREPLY=( $( compgen -W "${str2_option_args[*]}" -- "${curr_word}" ) ) + COMPREPLY=( $( compReplyArray "${str2_option_args[@]}" ) ) return $? ;; esac @@ -251,7 +286,7 @@ function _picocli_picocompletion-demo_sub1alias() { ;; --candidates) local IFS=$'\n' - COMPREPLY=( $( compgen -W "${str2_option_args[*]}" -- "${curr_word}" ) ) + COMPREPLY=( $( compReplyArray "${str2_option_args[@]}" ) ) return $? ;; esac @@ -297,8 +332,7 @@ function _picocli_picocompletion-demo_sub2() { local currIndex currIndex=$(currentPositionalIndex "sub2" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${possibilities_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${possibilities_pos_param_args[@]}" ) fi local IFS=$'\n' COMPREPLY=( $(compgen -W "${commands// /$'\n'}${IFS}${positionals}" -- "${curr_word}") ) @@ -337,8 +371,7 @@ function _picocli_picocompletion-demo_sub2alias() { local currIndex currIndex=$(currentPositionalIndex "sub2-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${possibilities_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${possibilities_pos_param_args[@]}" ) fi local IFS=$'\n' COMPREPLY=( $(compgen -W "${commands// /$'\n'}${IFS}${positionals}" -- "${curr_word}") ) @@ -419,7 +452,7 @@ function _picocli_picocompletion-demo_sub2_subsub2() { case ${prev_word} in -u|--timeUnit) local IFS=$'\n' - COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) + COMPREPLY=( $( compReplyArray "${timeUnit_option_args[@]}" ) ) return $? ;; -t|--timeout) @@ -435,8 +468,7 @@ function _picocli_picocompletion-demo_sub2_subsub2() { local currIndex currIndex=$(currentPositionalIndex "subsub2" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${str2_pos_param_args[@]}" ) fi local IFS=$'\n' COMPREPLY=( $(compgen -W "${commands// /$'\n'}${IFS}${positionals}" -- "${curr_word}") ) @@ -459,7 +491,7 @@ function _picocli_picocompletion-demo_sub2_sub2child2alias() { case ${prev_word} in -u|--timeUnit) local IFS=$'\n' - COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) + COMPREPLY=( $( compReplyArray "${timeUnit_option_args[@]}" ) ) return $? ;; -t|--timeout) @@ -475,8 +507,7 @@ function _picocli_picocompletion-demo_sub2_sub2child2alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child2-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${str2_pos_param_args[@]}" ) fi local IFS=$'\n' COMPREPLY=( $(compgen -W "${commands// /$'\n'}${IFS}${positionals}" -- "${curr_word}") ) @@ -500,8 +531,7 @@ function _picocli_picocompletion-demo_sub2_subsub3() { local currIndex currIndex=$(currentPositionalIndex "subsub3" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${cands_pos_param_args[@]}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames @@ -532,8 +562,7 @@ function _picocli_picocompletion-demo_sub2_sub2child3alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child3-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${cands_pos_param_args[@]}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames @@ -621,7 +650,7 @@ function _picocli_picocompletion-demo_sub2alias_subsub2() { case ${prev_word} in -u|--timeUnit) local IFS=$'\n' - COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) + COMPREPLY=( $( compReplyArray "${timeUnit_option_args[@]}" ) ) return $? ;; -t|--timeout) @@ -637,8 +666,7 @@ function _picocli_picocompletion-demo_sub2alias_subsub2() { local currIndex currIndex=$(currentPositionalIndex "subsub2" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${str2_pos_param_args[@]}" ) fi local IFS=$'\n' COMPREPLY=( $(compgen -W "${commands// /$'\n'}${IFS}${positionals}" -- "${curr_word}") ) @@ -661,7 +689,7 @@ function _picocli_picocompletion-demo_sub2alias_sub2child2alias() { case ${prev_word} in -u|--timeUnit) local IFS=$'\n' - COMPREPLY=( $( compgen -W "${timeUnit_option_args[*]}" -- "${curr_word}" ) ) + COMPREPLY=( $( compReplyArray "${timeUnit_option_args[@]}" ) ) return $? ;; -t|--timeout) @@ -677,8 +705,7 @@ function _picocli_picocompletion-demo_sub2alias_sub2child2alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child2-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${str2_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${str2_pos_param_args[@]}" ) fi local IFS=$'\n' COMPREPLY=( $(compgen -W "${commands// /$'\n'}${IFS}${positionals}" -- "${curr_word}") ) @@ -702,8 +729,7 @@ function _picocli_picocompletion-demo_sub2alias_subsub3() { local currIndex currIndex=$(currentPositionalIndex "subsub3" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${cands_pos_param_args[@]}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames @@ -734,8 +760,7 @@ function _picocli_picocompletion-demo_sub2alias_sub2child3alias() { local currIndex currIndex=$(currentPositionalIndex "sub2child3-alias" "${arg_opts}" "${flag_opts}") if (( currIndex >= 0 && currIndex <= 0 )); then - local IFS=$'\n' - positionals=$( compgen -W "${cands_pos_param_args[*]}" -- "${curr_word}" ) + positionals=$( compReplyArray "${cands_pos_param_args[@]}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then local IFS=$'\n' type compopt &>/dev/null && compopt -o filenames