Skip to main content
1 of 3
derobert
  • 113.3k
  • 20
  • 242
  • 289

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, if, 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, e.g., 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? E.g., if I'm sitting at:

anthony@Zia:~$ f 

how do customize completion so pressing tab would always 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.3k
  • 20
  • 242
  • 289