Marcus Marcus - 1 year ago 103
Bash Question

How Do I Enable Bash Programmable Completion for Command Line Switches?

On one of my systems, bash programmable completion works for basic commands like this:

$ ls -l t/
01_createTicket/ 02_methods.t

However, it does not work for the switches in my custom commands:

$ ./ --environment=test --verbosity=1 --test=t/
[will not autocomplete; does not show contents of directory]

On all my other systems, the second example works.

What exactly do I need to adjust on my system to enable bash completion on the end of a long command like that?

cxw cxw
Answer Source

Since your non-working system has autocompletion entries your working systems don't, as you saw in the complete -p output, run complete -r on the non-working system to clear out the completion entries (source).

Edit Completions may be loaded in any of the startup files: /etc/profile, ~/.bash_profile, ~/.bash_login, or ~/.profile. They are tested in that order (bash(1), section "Invocation"). I suspect your /etc/profile is loading the completions, which is why you need complete -r in your .bash_profile to clear them out.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download