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...

  • 1
    What's wrong with distributing a package?
    – dawud
    Jun 1, 2014 at 10:46
  • It might require root rights, which my script doesn't need. Jun 1, 2014 at 16:54

1 Answer 1


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
  • this will have to do! does anyone knows if there is a better mechanism in zsh for instance ? Jun 2, 2014 at 10:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .