-
-
Save jhsu/361298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bash completion for Ruby Version Manager (RVM) | |
__rvm_comp() | |
{ | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
COMPREPLY=($(compgen -W "$1" -- "$cur")) | |
return 0 | |
} | |
__rvm_subcommand() | |
{ | |
local word subcommand c=1 | |
while [ $c -lt $COMP_CWORD ]; do | |
word="${COMP_WORDS[c]}" | |
for subcommand in $1; do | |
if [ "$subcommand" = "$word" ]; then | |
echo "$subcommand" | |
return | |
fi | |
done | |
c=$((++c)) | |
done | |
} | |
__rvm_rubies () | |
{ | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
local rubies="$(rvm list strings 2>/dev/null)" | |
__rvm_comp "$rubies" | |
} | |
__rvm_gemsets () | |
{ | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
local gemsets="$(rvm gemset list | grep -v gemset 2>/dev/null)" | |
__rvm_comp "$gemsets" | |
} | |
_rvm_commands () | |
{ | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
COMMANDS='use info list reload impload update reset debug\ | |
install uninstall remove\ | |
ruby gem gemset rake tests spects\ | |
gemdir srcdir' | |
RVM_OPTS='\ | |
-v --version\ | |
-h --help\ | |
-l --level\ | |
--tag\ | |
--rev\ | |
--prefix\ | |
--bin\ | |
--source\ | |
--archives\ | |
-S --script\ | |
-G --gems\ | |
-C --configure\ | |
--reconfigure\ | |
--make\ | |
--make-install\ | |
--nice\ | |
-m --gem-set\ | |
--rm-gem-set' | |
completions="$COMMANDS $RVM_OPTS" | |
COMPREPLY=( $( compgen -W "$completions" -- "$cur" )) | |
return 0 | |
} | |
_rvm_use () | |
{ | |
local command="${COMP_WORDS[COMP_CWORD-2]}" cur="${COMP_WORDS[COMP_CWORD]}" | |
case "${command}" in | |
gemset) __rvm_gemsets ;; | |
*) __rvm_rubies ;; | |
esac | |
} | |
_rvm_install () | |
{ | |
local rubies="$(rvm list known)" | |
} | |
_rvm_gemset () | |
{ | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
local subcommands="use create" | |
local subcommand="$(__rvm_subcommand "$subcommands")" | |
if [ -z "$subcommand" ]; then | |
__rvm_comp "$subcommands" | |
return | |
fi | |
} | |
_rvm () | |
{ | |
local cur prev completions | |
cur=${COMP_WORDS[COMP_CWORD]} | |
prev=${COMP_WORDS[COMP_CWORD-1]} | |
case "${prev}" in | |
# install) _rvm_install ;; | |
use) _rvm_use ;; | |
gemset) _rvm_gemset ;; | |
*) _rvm_commands ;; | |
esac | |
return 0 | |
} | |
complete -o default -o nospace -F _rvm rvm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment