diff --git a/src/main/java/picocli/AutoComplete.java b/src/main/java/picocli/AutoComplete.java index a956cad68..c80dadaac 100644 --- a/src/main/java/picocli/AutoComplete.java +++ b/src/main/java/picocli/AutoComplete.java @@ -296,7 +296,7 @@ private static class CommandDescriptor { final String parentWithoutTopLevelCommand; final String commandName; final CommandLine commandLine; - + CommandDescriptor(String functionName, String parentWithoutTopLevelCommand, String commandName, CommandLine commandLine) { this.functionName = functionName; this.parentWithoutTopLevelCommand = parentWithoutTopLevelCommand; @@ -719,6 +719,7 @@ private static String generatePositionalParamsCases(List po buff.append(format("%s positionals=$( compgen -W \"$%s_pos_param_args\" -- \"%s\" )\n", indent, paramName, currWord)); } else if (type.equals(File.class) || "java.nio.file.Path".equals(type.getName())) { buff.append(format("%s %s (( currIndex >= %d && currIndex <= %d )); then\n", indent, ifOrElif, min, max)); + buff.append(format("%s local IFS=$'\\n'\n", indent)); buff.append(format("%s compopt -o filenames\n", indent)); buff.append(format("%s positionals=$( compgen -f -- \"%s\" ) # files\n", indent, currWord)); } else if (type.equals(InetAddress.class)) { @@ -763,6 +764,7 @@ private static String generateOptionsCases(List argOptionFields, Str buff.append(format("%s ;;\n", indent)); } else if (type.equals(File.class) || "java.nio.file.Path".equals(type.getName())) { buff.append(format("%s %s)\n", indent, concat("|", option.names()))); // " -f|--file)\n" + buff.append(format("%s local IFS=$'\\n'\n", indent)); buff.append(format("%s compopt -o filenames\n", indent)); buff.append(format("%s COMPREPLY=( $( compgen -f -- \"%s\" ) ) # files\n", indent, currWord)); buff.append(format("%s return $?\n", indent)); diff --git a/src/test/java/picocli/AutoCompleteTest.java b/src/test/java/picocli/AutoCompleteTest.java index a50718f87..f47eb3279 100644 --- a/src/test/java/picocli/AutoCompleteTest.java +++ b/src/test/java/picocli/AutoCompleteTest.java @@ -779,6 +779,7 @@ private String expectedCompletionScriptForAutoCompleteApp() { " return\n" + " ;;\n" + " -o|--completionScript)\n" + + " local IFS=$'\\n'\n" + " compopt -o filenames\n" + " COMPREPLY=( $( compgen -f -- \"${curr_word}\" ) ) # files\n" + " return $?\n" + diff --git a/src/test/resources/picocompletion-demo-help_completion.bash b/src/test/resources/picocompletion-demo-help_completion.bash index a362c97ca..52ee49dc1 100644 --- a/src/test/resources/picocompletion-demo-help_completion.bash +++ b/src/test/resources/picocompletion-demo-help_completion.bash @@ -257,6 +257,7 @@ function _picocli_picocompletion-demo-help_sub2() { return ;; --directory|-d) + local IFS=$'\n' compopt -o filenames COMPREPLY=( $( compgen -f -- "${curr_word}" ) ) # files return $? @@ -480,6 +481,7 @@ function _picocli_picocompletion-demo-help_sub2_subsub3() { if (( currIndex >= 0 && currIndex <= 0 )); then positionals=$( compgen -W "$cands_pos_param_args" -- "${curr_word}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then + local IFS=$'\n' compopt -o filenames positionals=$( compgen -f -- "${curr_word}" ) # files elif (( currIndex >= 3 && currIndex <= 2147483647 )); then diff --git a/src/test/resources/picocompletion-demo_completion.bash b/src/test/resources/picocompletion-demo_completion.bash index a6db9ffa9..a66ca6bd4 100644 --- a/src/test/resources/picocompletion-demo_completion.bash +++ b/src/test/resources/picocompletion-demo_completion.bash @@ -255,6 +255,7 @@ function _picocli_picocompletion-demo_sub2() { return ;; --directory|-d) + local IFS=$'\n' compopt -o filenames COMPREPLY=( $( compgen -f -- "${curr_word}" ) ) # files return $? @@ -461,6 +462,7 @@ function _picocli_picocompletion-demo_sub2_subsub3() { if (( currIndex >= 0 && currIndex <= 0 )); then positionals=$( compgen -W "$cands_pos_param_args" -- "${curr_word}" ) elif (( currIndex >= 1 && currIndex <= 2 )); then + local IFS=$'\n' compopt -o filenames positionals=$( compgen -f -- "${curr_word}" ) # files elif (( currIndex >= 3 && currIndex <= 2147483647 )); then