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

bash completion file issues #782

Closed
chino opened this issue Jun 1, 2016 · 13 comments
Closed

bash completion file issues #782

chino opened this issue Jun 1, 2016 · 13 comments

Comments

@chino
Copy link

chino commented Jun 1, 2016

Using brew install opensc (bottled version) and brew install --HEAD opensc (source built) on osx 10.11 Capitan generates the following errors when loading a bash prompt:

bash: /usr/local/etc/bash_completion.d/cardos-tool: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/cardos-tool: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/cryptoflex-tool: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/cryptoflex-tool: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/dnie-tool: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/dnie-tool: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/eidenv: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/eidenv: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/iasecc-tool: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/iasecc-tool: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/netkey-tool: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/netkey-tool: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/openpgp-tool: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/openpgp-tool: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/opensc-explorer: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/opensc-explorer: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/opensc-tool: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/opensc-tool: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/piv-tool: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/piv-tool: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/pkcs11-tool: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/pkcs11-tool: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/pkcs15-crypt: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/pkcs15-crypt: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/pkcs15-init: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/pkcs15-init: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/pkcs15-tool: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/pkcs15-tool: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/sc-hsm-tool: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/sc-hsm-tool: line 18: `                )'
bash: /usr/local/etc/bash_completion.d/westcos-tool: line 18: syntax error near unexpected token `)'
bash: /usr/local/etc/bash_completion.d/westcos-tool: line 18: `                )'

Which I believe is related to this location in the tools makefile:

| sed "s,OPTSWITHARGS,\

@frankmorgner
Copy link
Member

@eighthave could you have a look?

@eighthave
Copy link
Contributor

I'm not on OSX, so I can't run brew. @chino can you post one of those files here?

@chino
Copy link
Author

chino commented Jun 6, 2016

The OPTSWITHARGS replacement is leaving the case statement empty on line 18 of all those files.

Here is /usr/local/etc/bash_completion.d/westcos-tool:

# this was auto-generated by OpenSC/doc/tools/Makefile.am
_westcos_tool()
{
    COMPREPLY=()
    local cur prev split=false
    _get_comp_words_by_ref cur prev

    _split_longopt && split=true

    opts="      "

    if [ ${COMP_CWORD} -eq 1 ]; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi

    case "${prev}" in
                )
            return 0
            ;;
        *)
            COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
            return 0
            ;;
    esac

    $split && return 0

    if [[ "$cur" == -* ]]; then
        _longopt $1
        return
    fi

    _filedir
}
complete -F _westcos_tool westcos-tool


# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh

@michaelansel
Copy link
Contributor

It looks like the problem is the leading whitespace match. For some reason \s isn't matching and causing lines to be skipped (though I'm a bit confused why that is the case...) Unless there is a particular reason why we care that there is specifically whitespace, a .* match appears to fix the problem.

New command: sed -n 's,.*<option>\([^<]*\)</option>.*<replaceable>.*,\1,pg'

@michaelansel
Copy link
Contributor

Woohoo! Verified the fix using brew install --interactive and manually tweaking Makefile.am before running bootstrap/configure. I went ahead and updated all three places with the fix and it appears to work great now.

@michaelansel
Copy link
Contributor

Looking back at #238, I can't see any reason why the \s are explicitly necessary. I'll prep a PR with the fix.

michaelansel added a commit to michaelansel/OpenSC that referenced this issue Jun 9, 2016
Unnecessarily strict regex was failing for some unknown reason on OS X. Easier to just relax the regex than understand what's wrong (and then relax the regex).
Fixes OpenSC#782
@chino
Copy link
Author

chino commented Jun 10, 2016

You could try using the posix [[:space:]] iirc? or you can also explicitly write out the \s as [ \t\n] which should work too.

@michaelansel
Copy link
Contributor

True, but again, why is requiring leading whitespace important at all? The whole reason this is an issue is because the original regex was unnecessarily restrictive.

@chino
Copy link
Author

chino commented Jun 10, 2016

Oh, sure, if that's the case then I would agree.

@michaelansel
Copy link
Contributor

If you're interested in the fix prior to the next stable release: brew reinstall --HEAD opensc

@chino
Copy link
Author

chino commented Jun 24, 2016

Hm, this still hasn't made it's way upstream? Is it not possible to hot fix it so that brew updates without needing people to build off head inside their config management?

@frankmorgner
Copy link
Member

@chino we're not managing the package at brew

@udanieli
Copy link

Hello,
same issue on FreeBSD 10.3, using precompiled via pkg install

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

5 participants