Add bash completion

This commit is contained in:
Kenny Parnell 2016-02-29 02:53:43 -05:00
parent c071a97808
commit 0ed957b59e
2 changed files with 45 additions and 0 deletions

View File

@ -16,9 +16,11 @@ Depending on your OS, run the following
```bash
# For Ubuntu or other linux distros
echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc
echo '. $HOME/.asdf/completions/asdf.bash >> ~/.bashrc'
# OR for Max OSX
echo '. $HOME/.asdf/asdf.sh' >> ~/.bash_profile
echo '. $HOME/.asdf/completions/asdf.bash >> ~/.bash_profile'
```
If you use zsh or any other shell, replace `.bashrc` with the config file for the respective shell.

43
completions/asdf.bash Normal file
View File

@ -0,0 +1,43 @@
#!/usr/bin/env bash
_asdf () {
local cur=${COMP_WORDS[COMP_CWORD]}
local cmd=${COMP_WORDS[1]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
local plugins=$(asdf plugin-list | tr '\n' ' ')
COMPREPLY=()
case "$cmd" in
plugin-update)
COMPREPLY=($(compgen -W "$plugins --all" -- $cur))
;;
plugin-remove|which|list|list-all)
COMPREPLY=($(compgen -W "$plugins" -- $cur))
;;
install)
if [[ "$plugins" == *"$prev"* ]] ; then
local versions=$(asdf list-all $prev)
COMPREPLY=($(compgen -W "$versions" -- $cur))
else
COMPREPLY=($(compgen -W "$plugins" -- $cur))
fi
;;
uninstall|where|reshim)
if [[ "$plugins" == *"$prev"* ]] ; then
local versions=$(asdf list $prev)
COMPREPLY=($(compgen -W "$versions" -- $cur))
else
COMPREPLY=($(compgen -W "$plugins" -- $cur))
fi
;;
*)
local cmds='plugin-add plugin-list plugin-remove plugin-update install uninstall which where list list-all reshim'
COMPREPLY=($(compgen -W "$cmds" -- $cur))
;;
esac
return 0
}
complete -F _asdf asdf