Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a simple way to embed the completion features inside a script, for bash ?

I have a script that I want to redistribute, but I can't ask the people to add something inside their /etc/bash_completion.d in order for them to get the completion working fot my script...

share|improve this question
1  
What's wrong with distributing a package? –  dawud Jun 1 at 10:46
    
It might require root rights, which my script doesn't need. –  Jean-Michaël Celerier Jun 1 at 16:54

1 Answer 1

up vote 3 down vote accepted

There isn't a standard location for bash completions in home directories. You can either instruct people to copy your completion code into their .bashrc, or instruct them to save your completion definition script somewhere (which should not be on their $PATH) and to source it from their .bashrc. I recommend the latter since it makes upgrades a lot easier.

. ~/.bash_completions/jmc_app

Conventionally, your completions should be defined in a script with the same name as the program it completes for, containing a function definition with the same name with an underscore prepended, and calling complete to install the completion:

# jmc_app completion
_jmc_app () {
  …
}
complete -F _jmc_app jmc_app
share|improve this answer
    
this will have to do! does anyone knows if there is a better mechanism in zsh for instance ? –  Jean-Michaël Celerier Jun 2 at 10:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.