Merge pull request #31 from kennyp/bash-completion

Add bash completion. Thanks to @kennyp ~!
This commit is contained in:
Akash Manohar 2016-03-01 10:26:16 +05:30
commit c74f4a215d
2 changed files with 45 additions and 0 deletions

View File

@ -16,9 +16,11 @@ Depending on your OS, run the following
```bash ```bash
# For Ubuntu or other linux distros # For Ubuntu or other linux distros
echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc
echo '. $HOME/.asdf/completions/asdf.bash >> ~/.bashrc'
# OR for Max OSX # OR for Max OSX
echo '. $HOME/.asdf/asdf.sh' >> ~/.bash_profile 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. 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