Quick answer:
- Install
bash-completionbash-completion - Source
bash_completionbash_completiononBashstartup - Add your compspec on
Bashstartup - Don't overwrite
sudocompspec withcomplete -cf sudo
I suppose that you use MacOSX with brew.
Try:
brew update
brew install bash-completion
brew info bash-completion
# bash-completion: stable 1.3
. $(brew --prefix)/etc/bash_completion
complete -p sudo
You should see something like this:
complete -F _root_command sudo
Test:
function _comp_foo() { COMPREPLY=($(compgen -W 'a b c' -- "$2")); }
complete -F _comp_foo foo
Type foo SpaceTabTab
You should see a b c
Type sudo foo SpaceTabTab
You should see a b c
Then remove complete -fc sudo from your initialisation files (~/.bash_profile, ~/.bashrc etc)
Add the following lines to your initialisation files:
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
# Your compspec here
complete -o default -o nospace -W "$(sudo ls -1 /var/cache/salt/master/minions)" salt
Reopen terminal.
Type complete -p sudo.
You should see complete -F _root_command sudo.
Type complete -p salt.
You should see something like this:
complete -o default -o nospace -W 'a
b
c' salt
bash-completion2. note*:
You can install bash-completion2: https://github.com/Homebrew/homebrew/issues/19258
But:
2.*works withBash 4.*2.*uses the-Doption for compspecs lazy loading. So,complete -p sudooutputscomplete: sudo: no completion specificationuntil you typesudoSpaceTab