#!/usr/bin/env bash proc _asdf { local cur setglobal cur = $(COMP_WORDS[COMP_CWORD]) local cmd setglobal cmd = $(COMP_WORDS[1]) local prev setglobal prev = $(COMP_WORDS[COMP_CWORD-1]) local plugins setglobal plugins = $[asdf plugin-list | tr '\n' ' ] setglobal COMPREPLY = ''() match $cmd { with plugin-update setglobal COMPREPLY = ''($(compgen -W "$plugins --all" -- "$cur")) with plugin-remove|current|list|list-all setglobal COMPREPLY = ''($(compgen -W "$plugins" -- "$cur")) with install if [[ "$plugins" == *"$prev"* ]] { local versions setglobal versions = $[asdf list-all $prev] setglobal COMPREPLY = ''($(compgen -W "$versions" -- "$cur")) } else { setglobal COMPREPLY = ''($(compgen -W "$plugins" -- "$cur")) } with uninstall|where|reshim|local|global if [[ "$plugins" == *"$prev"* ]] { local versions setglobal versions = $[asdf list $prev] setglobal COMPREPLY = ''($(compgen -W "$versions" -- "$cur")) } else { setglobal COMPREPLY = ''($(compgen -W "$plugins" -- "$cur")) } with * local cmds='plugin-add plugin-list plugin-remove plugin-update install uninstall update current where which list list-all local global reshim' setglobal COMPREPLY = ''($(compgen -W "$cmds" -- "$cur")) } return 0 } complete -F _asdf asdf