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

ZSH Completions - parse error near `|' _msm:8: command not found: manager_property #387

Open
Next-Door-Tech opened this issue Oct 28, 2019 · 3 comments

Comments

@Next-Door-Tech
Copy link
Contributor

Next-Door-Tech commented Oct 28, 2019

Using ZSH on Debian 10, after loading the BASH completions file in .zshrc, trying to autocomplete msm commands results in an error.

I have ZSH loading the completions file with the following lines at the end of my .zshrc:

autoload -U +X compinit
compinit
autoload -U +X bashcompinit
bashcompinit
source /etc/bash_completion.d/msm

When I try to complete a command by typing

% sudo msm <tab>

I get

% sudo msm /etc/init.d/msm:1199: parse error near `|'
_msm:8: command not found: manager_property
                                 sudo msm
all       config    help      jargroup  restart   server    start     stop      update    version 

Further tab presses allow me to select an option, but further garbage is output to the prompt.

@Next-Door-Tech
Copy link
Contributor Author

Inspected /etc/init.d/msm at line 1199 and found

if [[ "$answer" =~ ^y|Y|yes$ ]]; then
    as_user "$SETTINGS_USERNAME" "rm -rf \"$SETTINGS_JAR_STORAGE_PATH/$1\""
    echo "Jar group deleted."
else
    echo "Jar group was NOT deleted."
fi

Investigating | chars inside test functions in ZSH

@Next-Door-Tech
Copy link
Contributor Author

Found changing line 1199
if [[ "$answer" =~ ^y|Y|yes$ ]]; then
to
if [[ "$answer" =~ (^y|Y|yes$) ]]; then
results in a new error referencing line 1796.

Changing
if [[ ! "$arg" =~ logroll|config ]]; then
to
if [[ ! "$arg" =~ (logroll|config) ]]; then
results in a new error when trying to tab complete:

sudo msm server_property:87: bad substitution
                                 sudo msm
all    config    help      jargroup  restart   server    sss       start     stop      update    version 

@Next-Door-Tech
Copy link
Contributor Author

Found bad substitution error at /etc/init.d/msm line 1847:

if [ -z "${!target_varname}" ]; then
    # if its still empty use the default value
    manager_property "DEFAULT_$2"
    server_set_property "$1" "$2" "\$SETTINGS_DEFAULT_$2"
fi

The error seems to be caused by the ${!target_varname} - ZSH arrays do not output the keys with ${!array}, instead it uses ${(k)array). So the ZSH-friendly version of the first line would be

if [ -z "${(k)target_varname}" ]; then
...

Not sure how to proceed from here without breaking the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant