Where to put bash completion scripts

Viewed 1954

I have implemented some perl scripts and in some cases i have to pass some command line args into my program.Usability perspective i have decided to add some bash completion script into my project.But now i am stuck on where to put my script to work it as expected.Please let me know where can i put my bash completion script

Custom Perl Scripts location

C:\scripts\tool\bin\ktools.pl

also add bin path to the system variable.

I have put my auto complete scripts in

C:\scripts\tool\bin\etc\bash_completion.d\ktools\foo

Bash Completion Script

_foo() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="--help --verbose --version"

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

Command should be auto suggested when user type ktools -- + press tab in command line or git bash.

2 Answers

The above answer is very inconvenient especially if you have multiple completion scripts and are having other people install and use your program.

The more convenient way to d it would be to create a folder containing all your completion scripts in /etc or such, and then in the .bashrc source everything in that directory.

Related