Add dynamic shell completion
Connect the hidden __complete helper to Bash or Zsh so that TAB completes service names, host addresses, and config files.
yoink completions <shell> completes subcommand names, flag names, and value enums. This page adds completion for service names, host addresses, and config file paths. The CLI reference describes the __complete helper that supplies these values.
Bash
-
Add this function to
~/.bashrc, alongsidesource <(yoink completions bash):# ~/.bashrc (alongside `source <(yoink completions bash)`) _yoink_dynamic() { local cur="${COMP_WORDS[COMP_CWORD]}" local prev="${COMP_WORDS[COMP_CWORD-1]}" # Forward any -c / --config that's already on the line so that # `yoink -c staging.yoink.yaml shell <TAB>` lists *staging's* # services, not the default config's. local fwd=() for ((i=1; i<COMP_CWORD; i++)); do case "${COMP_WORDS[i]}" in -c|--config) fwd=(-c "${COMP_WORDS[i+1]}") ;; esac done case "$prev" in -c|--config) COMPREPLY=( $(compgen -W "$(yoink __complete configs 2>/dev/null)" -- "$cur") ) return 0 ;; --service|-s|shell|ssh|exec|logs|restart|kill|debug|version|history|rollback|pull|diff) COMPREPLY=( $(compgen -W "$(yoink "${fwd[@]}" __complete services 2>/dev/null)" -- "$cur") ) return 0 ;; --host) COMPREPLY=( $(compgen -W "$(yoink "${fwd[@]}" __complete hosts 2>/dev/null)" -- "$cur") ) return 0 ;; esac } complete -F _yoink_dynamic -o default yoink -
Source
~/.bashrcagain.
Zsh
- Put the
compdefsnippet fromyoink completions zshinto yourfpath. - Add a wrapper that calls
yoink __complete <kind>for the values that you want.
The helper prints paths or names, separated by \n.
Make sure that completion works
Press <TAB> in each of these positions:
yoink -c <TAB> # all yoink configs in this repo
yoink shell <TAB> # services from the default config
yoink -c staging.yoink.yaml shell <TAB> # services from staging
See also
- CLI reference: the
__completesubcommands and their sources. - Install yoink: the installation of the binary.