Programmable Completion for Bash on macOS
https://itnext.io/programmable-completion-for-bash-on-macos-f81a0103080b
Most people are familiar with the default Bash completion functionality. You start typing a command, hit Tab, and the command gets automatically completed. If there are multiple commands that match what you typed so far, you can hit Tab two times, and Bash displays a list of all possible completions. The same works for variables and filenames.
However, many people don’t know that Bash supports a much more advanced type of completion, called programmable completion. This allows to define command-specific completion logic, which enables users to auto-complete sub-commands, options, and other arguments of commands in a context-specific manner. Just imagine typing cmd -[tab][tab] and then see a list of all applicable options for this command.