Consider:
$ ssh fo<tab>
foo fool football
How would I write a for loop to iterate over those values?
#!/usr/bin/env bash
for SERVER in $(ssh fo<MAGIC HERE>) ; do echo $SERVER ; done
The list could change regularly, so hardcoding the values is not an option. In the specific case of SSH, I understand that I could grep the SSH config file for the matching hosts. But some other completion situations arise, such as:
$ git che<tab>
checkout cherry cherry-pick
The answer should be useful for these other ad-hoc completions as well.
It has been extensively documented that programmers are willing to put in long hours of effort in order to save ten minutes of "unnecessary" labor. This is known as optimization.
git
sub-commands?ls -
would return onlyls --
and needs processing again to get all compination after that.