Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path completion not working with directory names #1863

Merged
merged 3 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${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// /$'\n'}${IFS}${positionals}" -- "${curr_word}") )
fi
}

Expand Down
Loading