MacOS – Bash Tab-Completion for OSX Specific commands

bashmacosterminal

I've been looking around and I can't seem to find a bash completion rule set for macOS specific utilities. (i.e. diskutil, kext(*whatever), networksetup, defaults, launchctl, etc.) comparable to tab-completion for git commands.

Specifically, I would like to have TAB print a list of the options for the tool.

Does that exist?

Best Answer

If you use a package manager (Homebrew, MacPorts, etc) it's worth checking if it provides any - brew search completion returns launchctl-completion, for example, though the other tools you mention aren't listed. You don't mention tmutil, but if it's useful there's a completion for it here:

#!/usr/bin/env bash 
### 補完関数。
_tmutil(){
  list=$( tmutil | /usr/bin/grep -v ^$ | /usr/bin/grep ^Usage | awk '{print $3}' )
  COMPREPLY=( $(compgen -W "$list" ${COMP_WORDS[COMP_CWORD]}  ) ) 
}
complete -F _tmutil tmutil

That might also be a good basis for hacking your own completions?