Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash completion doesn't work for MSYS bash. Regex syntax error

I tried to install bash-completion for MSYS bash, but it seems it contains some syntax errors. It fails with the following message

bash: /usr/local/share/bash-completion/bash_completion: line 625: syntax error in conditional expression: unexpected token `('
bash: /usr/local/share/bash-completion/bash_completion: line 625: syntax error near `^(\'
bash: /usr/local/share/bash-completion/bash_completion: line 625: `    if [[ $cur =~ ^(\$\{?)([A-Za-z0-9_]*)$ ]]; then'

here is the code that fails

# Complete variables.
# @return  True (0) if variables were completed, 
#          False (> 0) if not.
_variables()
{
    if [[ $cur =~ ^(\$\{?)([A-Za-z0-9_]*)$ ]]; then
        [[ $cur == *{* ]] && local suffix=} || local suffix=
        COMPREPLY+=( $( compgen -P ${BASH_REMATCH[1]} -S "$suffix" -v -- \
            "${BASH_REMATCH[2]}" ) )
        return 0
    fi
    return 1
}
like image 370
Nekuromento Avatar asked Jun 16 '26 01:06

Nekuromento


1 Answers

You are using the beta version (1.99) of bash-completion, you can try the latest stable instead (1.3)

If you really need the beta version you need quotes around the regular expression ^(\$\{?)([A-Za-z0-9_]*)$ in the line if [[ $cur =~ ^(\$\{?)([A-Za-z0-9_]*)$ ]]; then handling of the operator =~ is different depending on bash version (IIRC prior 3.2 quotes are required)

like image 112
Sorin Avatar answered Jun 19 '26 18:06

Sorin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!