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 autocomplete script errors in zsh #425

Merged
merged 2 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 13 additions & 6 deletions src/main/java/picocli/AutoComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,19 @@ public boolean equals(Object obj) {
"# [1] http://stackoverflow.com/a/12495480/1440785\n" +
"# [2] http://tiswww.case.edu/php/chet/bash/FAQ\n" +
"# [3] https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html\n" +
"# [4] https://stackoverflow.com/questions/17042057/bash-check-element-in-array-for-elements-in-another-array/17042655#17042655\n" +
"# [5] https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion\n" +
"# [4] http://zsh.sourceforge.net/Doc/Release/Options.html#index-COMPLETE_005fALIASES\n" +
"# [5] https://stackoverflow.com/questions/17042057/bash-check-element-in-array-for-elements-in-another-array/17042655#17042655\n" +
"# [6] https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion\n" +
"#\n" +
"\n" +
"# Enable programmable completion facilities (see [3])\n" +
"shopt -s progcomp\n" +
"if [ -n \"$BASH_VERSION\" ]; then\n" +
" # Enable programmable completion facilities when using bash (see [3])\n" +
" shopt -s progcomp\n" +
"elif [ -n \"$ZSH_VERSION\" ]; then\n" +
" # Make alias a distinct command for completion purposes when using zsh (see [4])\n" +
" setopt COMPLETE_ALIASES\n" +
" alias compopt=complete\n" +
"fi\n" +
"\n" +
"# ArrContains takes two arguments, both of which are the name of arrays.\n" +
"# It creates a temporary hash from lArr1 and then checks if all elements of lArr2\n" +
Expand All @@ -266,7 +273,7 @@ public boolean equals(Object obj) {
"# Returns zero (no error) if all elements of the 2nd array are in the 1st array,\n" +
"# otherwise returns 1 (error).\n" +
"#\n" +
"# Modified from [4]\n" +
"# Modified from [5]\n" +
"function ArrContains() {\n" +
" local lArr1 lArr2\n" +
" declare -A tmp\n" +
Expand All @@ -282,7 +289,7 @@ public boolean equals(Object obj) {
"\n" +
"# Define a completion specification (a compspec) for the\n" +
"# `%1$s`, `%1$s.sh`, and `%1$s.bash` commands.\n" +
"# Uses the bash `complete` builtin (see [5]) to specify that shell function\n" +
"# Uses the bash `complete` builtin (see [6]) to specify that shell function\n" +
"# `_complete_%1$s` is responsible for generating possible completions for the\n" +
"# current word on the command line.\n" +
"# The `-o default` option means that if the function generated no matches, the\n" +
Expand Down
19 changes: 13 additions & 6 deletions src/test/java/picocli/AutoCompleteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,19 @@ public void testAutoCompleteAppBothScriptFilesForceOverwrite() throws Exception
"# [1] http://stackoverflow.com/a/12495480/1440785\n" +
"# [2] http://tiswww.case.edu/php/chet/bash/FAQ\n" +
"# [3] https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html\n" +
"# [4] https://stackoverflow.com/questions/17042057/bash-check-element-in-array-for-elements-in-another-array/17042655#17042655\n" +
"# [5] https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion\n" +
"# [4] http://zsh.sourceforge.net/Doc/Release/Options.html#index-COMPLETE_005fALIASES\n" +
"# [5] https://stackoverflow.com/questions/17042057/bash-check-element-in-array-for-elements-in-another-array/17042655#17042655\n" +
"# [6] https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion\n" +
"#\n" +
"\n" +
"# Enable programmable completion facilities (see [3])\n" +
"shopt -s progcomp\n" +
"if [ -n \"$BASH_VERSION\" ]; then\n" +
" # Enable programmable completion facilities when using bash (see [3])\n" +
" shopt -s progcomp\n" +
"elif [ -n \"$ZSH_VERSION\" ]; then\n" +
" # Make alias a distinct command for completion purposes when using zsh (see [4])\n" +
" setopt COMPLETE_ALIASES\n" +
" alias compopt=complete\n" +
"fi\n" +
"\n" +
"# ArrContains takes two arguments, both of which are the name of arrays.\n" +
"# It creates a temporary hash from lArr1 and then checks if all elements of lArr2\n" +
Expand All @@ -357,7 +364,7 @@ public void testAutoCompleteAppBothScriptFilesForceOverwrite() throws Exception
"# Returns zero (no error) if all elements of the 2nd array are in the 1st array,\n" +
"# otherwise returns 1 (error).\n" +
"#\n" +
"# Modified from [4]\n" +
"# Modified from [5]\n" +
"function ArrContains() {\n" +
" local lArr1 lArr2\n" +
" declare -A tmp\n" +
Expand Down Expand Up @@ -410,7 +417,7 @@ public void testAutoCompleteAppBothScriptFilesForceOverwrite() throws Exception
"\n" +
"# Define a completion specification (a compspec) for the\n" +
"# `picocli.AutoComplete`, `picocli.AutoComplete.sh`, and `picocli.AutoComplete.bash` commands.\n" +
"# Uses the bash `complete` builtin (see [5]) to specify that shell function\n" +
"# Uses the bash `complete` builtin (see [6]) to specify that shell function\n" +
"# `_complete_picocli.AutoComplete` is responsible for generating possible completions for the\n" +
"# current word on the command line.\n" +
"# The `-o default` option means that if the function generated no matches, the\n" +
Expand Down
19 changes: 13 additions & 6 deletions src/test/resources/basic.bash
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@
# [1] http://stackoverflow.com/a/12495480/1440785
# [2] http://tiswww.case.edu/php/chet/bash/FAQ
# [3] https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html
# [4] https://stackoverflow.com/questions/17042057/bash-check-element-in-array-for-elements-in-another-array/17042655#17042655
# [5] https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion
# [4] http://zsh.sourceforge.net/Doc/Release/Options.html#index-COMPLETE_005fALIASES
# [5] https://stackoverflow.com/questions/17042057/bash-check-element-in-array-for-elements-in-another-array/17042655#17042655
# [6] https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion
#

# Enable programmable completion facilities (see [3])
shopt -s progcomp
if [ -n "$BASH_VERSION" ]; then
# Enable programmable completion facilities when using bash (see [3])
shopt -s progcomp
elif [ -n "$ZSH_VERSION" ]; then
# Make alias a distinct command for completion purposes when using zsh (see [4])
setopt COMPLETE_ALIASES
alias compopt=complete
fi

# ArrContains takes two arguments, both of which are the name of arrays.
# It creates a temporary hash from lArr1 and then checks if all elements of lArr2
Expand All @@ -50,7 +57,7 @@ shopt -s progcomp
# Returns zero (no error) if all elements of the 2nd array are in the 1st array,
# otherwise returns 1 (error).
#
# Modified from [4]
# Modified from [5]
function ArrContains() {
local lArr1 lArr2
declare -A tmp
Expand Down Expand Up @@ -102,7 +109,7 @@ function _picocli_basicExample() {

# Define a completion specification (a compspec) for the
# `basicExample`, `basicExample.sh`, and `basicExample.bash` commands.
# Uses the bash `complete` builtin (see [5]) to specify that shell function
# Uses the bash `complete` builtin (see [6]) to specify that shell function
# `_complete_basicExample` is responsible for generating possible completions for the
# current word on the command line.
# The `-o default` option means that if the function generated no matches, the
Expand Down
19 changes: 13 additions & 6 deletions src/test/resources/hyphenated_completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@
# [1] http://stackoverflow.com/a/12495480/1440785
# [2] http://tiswww.case.edu/php/chet/bash/FAQ
# [3] https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html
# [4] https://stackoverflow.com/questions/17042057/bash-check-element-in-array-for-elements-in-another-array/17042655#17042655
# [5] https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion
# [4] http://zsh.sourceforge.net/Doc/Release/Options.html#index-COMPLETE_005fALIASES
# [5] https://stackoverflow.com/questions/17042057/bash-check-element-in-array-for-elements-in-another-array/17042655#17042655
# [6] https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion
#

# Enable programmable completion facilities (see [3])
shopt -s progcomp
if [ -n "$BASH_VERSION" ]; then
# Enable programmable completion facilities when using bash (see [3])
shopt -s progcomp
elif [ -n "$ZSH_VERSION" ]; then
# Make alias a distinct command for completion purposes when using zsh (see [4])
setopt COMPLETE_ALIASES
alias compopt=complete
fi

# ArrContains takes two arguments, both of which are the name of arrays.
# It creates a temporary hash from lArr1 and then checks if all elements of lArr2
Expand All @@ -50,7 +57,7 @@ shopt -s progcomp
# Returns zero (no error) if all elements of the 2nd array are in the 1st array,
# otherwise returns 1 (error).
#
# Modified from [4]
# Modified from [5]
function ArrContains() {
local lArr1 lArr2
declare -A tmp
Expand Down Expand Up @@ -117,7 +124,7 @@ function _picocli_rcmd_sub2() {

# Define a completion specification (a compspec) for the
# `rcmd`, `rcmd.sh`, and `rcmd.bash` commands.
# Uses the bash `complete` builtin (see [5]) to specify that shell function
# Uses the bash `complete` builtin (see [6]) to specify that shell function
# `_complete_rcmd` is responsible for generating possible completions for the
# current word on the command line.
# The `-o default` option means that if the function generated no matches, the
Expand Down
19 changes: 13 additions & 6 deletions src/test/resources/picocompletion-demo_completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@
# [1] http://stackoverflow.com/a/12495480/1440785
# [2] http://tiswww.case.edu/php/chet/bash/FAQ
# [3] https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html
# [4] https://stackoverflow.com/questions/17042057/bash-check-element-in-array-for-elements-in-another-array/17042655#17042655
# [5] https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion
# [4] http://zsh.sourceforge.net/Doc/Release/Options.html#index-COMPLETE_005fALIASES
# [5] https://stackoverflow.com/questions/17042057/bash-check-element-in-array-for-elements-in-another-array/17042655#17042655
# [6] https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion
#

# Enable programmable completion facilities (see [3])
shopt -s progcomp
if [ -n "$BASH_VERSION" ]; then
# Enable programmable completion facilities when using bash (see [3])
shopt -s progcomp
elif [ -n "$ZSH_VERSION" ]; then
# Make alias a distinct command for completion purposes when using zsh (see [4])
setopt COMPLETE_ALIASES
alias compopt=complete
fi

# ArrContains takes two arguments, both of which are the name of arrays.
# It creates a temporary hash from lArr1 and then checks if all elements of lArr2
Expand All @@ -50,7 +57,7 @@ shopt -s progcomp
# Returns zero (no error) if all elements of the 2nd array are in the 1st array,
# otherwise returns 1 (error).
#
# Modified from [4]
# Modified from [5]
function ArrContains() {
local lArr1 lArr2
declare -A tmp
Expand Down Expand Up @@ -209,7 +216,7 @@ function _picocli_picocompletion-demo_sub2_subsub2() {

# Define a completion specification (a compspec) for the
# `picocompletion-demo`, `picocompletion-demo.sh`, and `picocompletion-demo.bash` commands.
# Uses the bash `complete` builtin (see [5]) to specify that shell function
# Uses the bash `complete` builtin (see [6]) to specify that shell function
# `_complete_picocompletion-demo` is responsible for generating possible completions for the
# current word on the command line.
# The `-o default` option means that if the function generated no matches, the
Expand Down