01 / JUST GIVE ME THE ANSWER
The quick answer
Programmable completion functions inspect the current command line and populate COMPREPLY with candidate completions.
COMP_WORDS COMP_CWORD COMPREPLY02 / EXPLAIN IT PROPERLY
What's going on?
Programmable completion functions inspect the current command line and populate COMPREPLY with candidate completions.
Understanding the underlying mechanism makes troubleshooting much easier than memorising a command in isolation.
03 / UNDER THE BONNET
Dig a little deeper
COMP_WORDS is an array of parsed words; COMP_CWORD is the index of the word under the cursor; COMPREPLY is the output array. COMP_LINE and COMP_POINT help with finer-grained parsing.
04 / TRY IT YOURSELF
Hands-on commands
Try these in a suitable test environment. Read each command before running it, especially if you have elevated privileges.
complete -p | head
help complete
help compgen05 / THE RABBIT HOLE
One more thing...
Tab is a tiny key with enormous ambitions.
Explore another mystery ↗