5

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.

gihan-maduranga
  • 4,049
  • 3
  • 40
  • 73

2 Answers2

5

I'm pretty sure you need to source it into your .bashrc (basically include it).

Open ~/.bashrc and write (you might need to create it if it doesn't exists)

source your_bash_file

Then, in your terminal, "refresh" by doing

source ~/.bashrc

and it should work.

math2001
  • 3,848
  • 23
  • 33
1

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.

PreciseMotion
  • 332
  • 1
  • 12