28

How does Bash in Ubuntu know a tool's specific list of actions?

For example if I type apt-get and tab twice I only see remove, update, upgrade ...etc, but not the actions for another command or the files in the current directory.

I'm developing a command-line tool in Go and would like to provide this feature for the distros that support it.

2
  • 1
    I removed "ubuntu" from your title and tags since this is better as a more general question (the answer isn't specific to any distro).
    – goldilocks
    Aug 11, 2014 at 18:55
  • 1
    Great question, I've often wondered this, but never took the time to look it up. Aug 18, 2014 at 20:14

1 Answer 1

28

It does this using bash v4's completion features. The completion code for apt-get is provided by the bash-completion package and located at /usr/share/bash-completion/completions/apt-get. Applications that have completion and are not part of the base bash-completion package place their completion scripts in /etc/bash_completion.d.

The completions are loaded via sourcing /etc/bash_completion. Exactly where this is done will vary depending on Debian or Ubuntu versions. That in turn will source everything in /usr/share/bash-completion/completions and /etc/bash_completion.d.

2
  • 1
    Thanks, that explains it. So the implementation no only varies from Debian to Ubuntu, but also in each version of the same distribution? Aug 11, 2014 at 17:57
  • 3
    @Amgad It works the same way on all distributions. The only differences are where the files are located, and perhaps some default settings. Aug 11, 2014 at 23:32

You must log in to answer this question.

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