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.

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.

share|improve this question
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 at 18:55
    
Great question, I've often wondered this, but never took the time to look it up. –  akatakritos Aug 18 at 20:14

1 Answer 1

up vote 12 down vote accepted

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.

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

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.