Skip to content

Commit

Permalink
Fix path completion not working with directory names
Browse files Browse the repository at this point in the history
  • Loading branch information
NewbieOrange committed Oct 27, 2022
1 parent 5098341 commit 3ff446c
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 47 deletions.
3 changes: 2 additions & 1 deletion src/main/java/picocli/AutoComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ private static String generateFunctionForCommand(String functionName, String com
" else\n" +
" local positionals=\"\"\n" +
"%s" +
" COMPREPLY=( $(compgen -W \"${commands} ${positionals}\" -- \"${curr_word}\") )\n" +
" local IFS=$'\\n'\n" +
" COMPREPLY=( $(compgen -W \"${commands}${IFS}${positionals}\" -- \"${curr_word}\") )\n" +
" fi\n" +
"}\n";

Expand Down
18 changes: 12 additions & 6 deletions src/test/java/picocli/AutoCompleteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,8 @@ private String expectedCompletionScriptForAutoCompleteApp() {
" COMPREPLY=( $(compgen -W \"${flag_opts} ${arg_opts}\" -- \"${curr_word}\") )\n" +
" else\n" +
" local positionals=\"\"\n" +
" COMPREPLY=( $(compgen -W \"${commands} ${positionals}\" -- \"${curr_word}\") )\n" +
" local IFS=$'\\n'\n" +
" COMPREPLY=( $(compgen -W \"${commands}${IFS}${positionals}\" -- \"${curr_word}\") )\n" +
" fi\n" +
"}\n" +
"\n" +
Expand Down Expand Up @@ -1004,7 +1005,8 @@ private String expectedCompletionScriptForNonDefault() {
" COMPREPLY=( $(compgen -W \"${flag_opts} ${arg_opts}\" -- \"${curr_word}\") )\n" +
" else\n" +
" local positionals=\"\"\n" +
" COMPREPLY=( $(compgen -W \"${commands} ${positionals}\" -- \"${curr_word}\") )\n" +
" local IFS=$'\\n'\n" +
" COMPREPLY=( $(compgen -W \"${commands}${IFS}${positionals}\" -- \"${curr_word}\") )\n" +
" fi\n" +
"}\n" +
"\n" +
Expand Down Expand Up @@ -1563,7 +1565,8 @@ private String getCompletionScriptText(String cmdName) {
" COMPREPLY=( $(compgen -W \"${flag_opts} ${arg_opts}\" -- \"${curr_word}\") )\n" +
" else\n" +
" local positionals=\"\"\n" +
" COMPREPLY=( $(compgen -W \"${commands} ${positionals}\" -- \"${curr_word}\") )\n" +
" local IFS=$'\\n'\n" +
" COMPREPLY=( $(compgen -W \"${commands}${IFS}${positionals}\" -- \"${curr_word}\") )\n" +
" fi\n" +
"}\n" +
"\n" +
Expand All @@ -1580,7 +1583,8 @@ private String getCompletionScriptText(String cmdName) {
" COMPREPLY=( $(compgen -W \"${flag_opts} ${arg_opts}\" -- \"${curr_word}\") )\n" +
" else\n" +
" local positionals=\"\"\n" +
" COMPREPLY=( $(compgen -W \"${commands} ${positionals}\" -- \"${curr_word}\") )\n" +
" local IFS=$'\\n'\n" +
" COMPREPLY=( $(compgen -W \"${commands}${IFS}${positionals}\" -- \"${curr_word}\") )\n" +
" fi\n" +
"}\n" +
"\n" +
Expand Down Expand Up @@ -1785,7 +1789,8 @@ private String getCompletionScriptTextWithHidden(String commandName) {
" COMPREPLY=( $(compgen -W \"${flag_opts} ${arg_opts}\" -- \"${curr_word}\") )\n" +
" else\n" +
" local positionals=\"\"\n" +
" COMPREPLY=( $(compgen -W \"${commands} ${positionals}\" -- \"${curr_word}\") )\n" +
" local IFS=$'\\n'\n" +
" COMPREPLY=( $(compgen -W \"${commands}${IFS}${positionals}\" -- \"${curr_word}\") )\n" +
" fi\n" +
"}\n" +
"\n" +
Expand All @@ -1802,7 +1807,8 @@ private String getCompletionScriptTextWithHidden(String commandName) {
" COMPREPLY=( $(compgen -W \"${flag_opts} ${arg_opts}\" -- \"${curr_word}\") )\n" +
" else\n" +
" local positionals=\"\"\n" +
" COMPREPLY=( $(compgen -W \"${commands} ${positionals}\" -- \"${curr_word}\") )\n" +
" local IFS=$'\\n'\n" +
" COMPREPLY=( $(compgen -W \"${commands}${IFS}${positionals}\" -- \"${curr_word}\") )\n" +
" fi\n" +
"}\n" +
"\n" +
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/bashify_completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ function _picocli_bashify() {
COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") )
else
local positionals=""
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/basic.bash
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ function _picocli_basicExample() {
COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") )
else
local positionals=""
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down
9 changes: 6 additions & 3 deletions src/test/resources/hyphenated_completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ function _picocli_rcmd() {
COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") )
else
local positionals=""
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand All @@ -172,7 +173,8 @@ function _picocli_rcmd_sub1() {
COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") )
else
local positionals=""
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand All @@ -198,7 +200,8 @@ function _picocli_rcmd_sub2() {
COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") )
else
local positionals=""
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down
54 changes: 36 additions & 18 deletions src/test/resources/picocompletion-demo-help_completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ function _picocli_picocompletion-demo-help() {
COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") )
else
local positionals=""
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -225,7 +226,8 @@ function _picocli_picocompletion-demo-help_sub1() {
COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") )
else
local positionals=""
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -259,7 +261,8 @@ function _picocli_picocompletion-demo-help_sub1alias() {
COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") )
else
local positionals=""
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -297,7 +300,8 @@ function _picocli_picocompletion-demo-help_sub2() {
if (( currIndex >= 0 && currIndex <= 0 )); then
positionals=$( compgen -W "$possibilities_pos_param_args" -- "${curr_word}" )
fi
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -335,7 +339,8 @@ function _picocli_picocompletion-demo-help_sub2alias() {
if (( currIndex >= 0 && currIndex <= 0 )); then
positionals=$( compgen -W "$possibilities_pos_param_args" -- "${curr_word}" )
fi
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand All @@ -352,7 +357,8 @@ function _picocli_picocompletion-demo-help_help() {
COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") )
else
local positionals=""
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -380,7 +386,8 @@ function _picocli_picocompletion-demo-help_sub2_subsub1() {
COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") )
else
local positionals=""
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -408,7 +415,8 @@ function _picocli_picocompletion-demo-help_sub2_sub2child1alias() {
COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") )
else
local positionals=""
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -445,7 +453,8 @@ function _picocli_picocompletion-demo-help_sub2_subsub2() {
if (( currIndex >= 0 && currIndex <= 0 )); then
positionals=$( compgen -W "$str2_pos_param_args" -- "${curr_word}" )
fi
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -482,7 +491,8 @@ function _picocli_picocompletion-demo-help_sub2_sub2child2alias() {
if (( currIndex >= 0 && currIndex <= 0 )); then
positionals=$( compgen -W "$str2_pos_param_args" -- "${curr_word}" )
fi
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -512,7 +522,8 @@ function _picocli_picocompletion-demo-help_sub2_subsub3() {
type compopt &>/dev/null && compopt -o filenames
positionals=$( compgen -A hostname -- "${curr_word}" )
fi
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -542,7 +553,8 @@ function _picocli_picocompletion-demo-help_sub2_sub2child3alias() {
type compopt &>/dev/null && compopt -o filenames
positionals=$( compgen -A hostname -- "${curr_word}" )
fi
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -570,7 +582,8 @@ function _picocli_picocompletion-demo-help_sub2alias_subsub1() {
COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") )
else
local positionals=""
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -598,7 +611,8 @@ function _picocli_picocompletion-demo-help_sub2alias_sub2child1alias() {
COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") )
else
local positionals=""
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -635,7 +649,8 @@ function _picocli_picocompletion-demo-help_sub2alias_subsub2() {
if (( currIndex >= 0 && currIndex <= 0 )); then
positionals=$( compgen -W "$str2_pos_param_args" -- "${curr_word}" )
fi
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -672,7 +687,8 @@ function _picocli_picocompletion-demo-help_sub2alias_sub2child2alias() {
if (( currIndex >= 0 && currIndex <= 0 )); then
positionals=$( compgen -W "$str2_pos_param_args" -- "${curr_word}" )
fi
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -702,7 +718,8 @@ function _picocli_picocompletion-demo-help_sub2alias_subsub3() {
type compopt &>/dev/null && compopt -o filenames
positionals=$( compgen -A hostname -- "${curr_word}" )
fi
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down Expand Up @@ -732,7 +749,8 @@ function _picocli_picocompletion-demo-help_sub2alias_sub2child3alias() {
type compopt &>/dev/null && compopt -o filenames
positionals=$( compgen -A hostname -- "${curr_word}" )
fi
COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") )
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${commands}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down
Loading

0 comments on commit 3ff446c

Please sign in to comment.