Skip to main content
3 of 3
improved spelling and punctuation
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

How to customize Bash command completion?

In bash, it's easy enough to set up customized completion of command arguments using the complete built-in. For example, for a hypothetical command with a synopsis of

foo --a | --b | --c

you could do

complete -W '--a --b --c' foo

You can also customize the completion you get when you press Tab at an empty prompt using complete -E, for example complete -E -W 'foo bar'. Then, pressing tab at the empty prompt would suggest only foo and bar.

How do I customize command completion at a non-empty prompt? For example, if I write f, how do I customize the completion to make it complete to foo?

(The actual case I'd like is locTABlocalc. And my brother, who prompted me to ask this, wants it with mplayer.)

derobert
  • 113.2k
  • 20
  • 242
  • 289