Bash completion for Maven escapes colon

前端 未结 4 1104
粉色の甜心
粉色の甜心 2020-12-30 06:42

I added bash completion for Maven following the docs:

http://maven.apache.org/guides/mini/guide-bash-m2-completion.html

Everything works well except for goal

相关标签:
4条回答
  • 2020-12-30 06:58

    Any suggestions how this can be fixed? I'm using Ubuntu 8.10 (2.6.27-17-generic) and

    Dennis answer is definitely correct.

    But for the record, there is a logged issue (MNG-3928) to improve the documentation about the Maven integration with bash. The issue has a script attached which is an improved version of the one currently online and just works. You might want to give it a try.

    Personally, I use the Bash Completion script from Ludovic Claude's PPA (the one that is bundled into the maven package from Ubuntu) that I download directly from bazaar (her e is a direct download link to the HEAD revision). It is just awesome.

    0 讨论(0)
  • 2020-12-30 07:10

    I'd go with the Maven2 Bash Completion File at willcodeforbeer.com.

    • works great
    • handles colons
    • doesn't muck up global variable COMP_WORDBREAKS (thereby breaking scp, etc)
    • easy to edit and understand

    Hope that helps!

    0 讨论(0)
  • 2020-12-30 07:16

    From Bash FAQ E13.

    Just after the complete command in the script you linked to, issue this command to remove the colon from the list of completion word break characters:

    COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
    
    0 讨论(0)
  • 2020-12-30 07:24

    Here is a related question and another suggested solution:

    How to reset COMP_WORDBREAKS without effecting other completion script?

    As stated before, the simplest solution is to alter COMP_WORDBREAKS. However, modifying COMP_WORDBREAKS in your completion script is not safe (as it is a global variable and it has the side effect of affecting the behavior of other completion scripts - for example scp).

    Therefore, bash completion offers some helper methods which you can use to achieve your goal in a better and more safer way.

    Two helper methods were added in Bash completion 1.2 for this:

    • _get_comp_words_by_ref with the -n EXCLUDE option
      • gets the word-to-complete without considering the characters in EXCLUDE as word breaks
    • __ltrim_colon_completions
      • removes colon containing prefix from COMPREPLY items
        (a workaround for http://tiswww.case.edu/php/chet/bash/FAQ - E13)

    So, here is a basic example of how to a handle a colon (:) in completion words:

    _mytool()
    {
        local cur
        _get_comp_words_by_ref -n : cur
    
        # my implementation here
    
        __ltrim_colon_completions "$cur"
    }
    complete -F _mytool mytool
    

    Using the helper methods also simplifies the completion script and ensures that you get the same behavior on any environment (bash-3 or bash-4).

    You can also take a look at man or perl completion scripts in /etc/bash_completion.d to see how they use the above helper methods to solve this problem.

    0 讨论(0)
提交回复
热议问题