Bash – compgen : ignoring case

autocompletebash

I'm trying to implement a custom bash completion as described here. However, it seems that compgen is case-sensitive. Is there a way to turn it case-insensitive in that context ?

Best Answer

I would modify the example from the link you mentioned into something like this:

_foo() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD],,}"     # this downcases the result
    prev="${COMP_WORDS[COMP_CWORD-1],,}"  # here too
    opts="--help --verbose --version"

    if [[ ${cur} == -* ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -F _foo foo

For more info refer to the bash documentation or the bash hackers site.

Related Question