Sha256: 3fd1fa664827603c45475b0cd9fbf72ba4eb86aace0d54478fb40822dcc4d648

Contents?: true

Size: 1.91 KB

Versions: 4

Compression:

Stored size: 1.91 KB

Contents

# 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 ()
{
  echo "$(rvm list strings) default system"
}

__rvm_gemsets ()
{
  echo "$(rvm gemset list | grep -v gemset 2>/dev/null)"
}

_rvm_commands ()
{
  local cur=${COMP_WORDS[COMP_CWORD]}

  COMMANDS='\
        version use reload implode update reset info debug\
        install uninstall remove\
        ruby gem rake tests specs monitor gemset\
        gemdir srcdir fetch list package notes snapshot'

  case "${cur}" in
  -*)       _rvm_opts ;;
  *)        __rvm_comp "$COMMANDS $(__rvm_rubies)" ;;
  esac
}

_rvm_opts ()
{
  RVM_OPTS='\
    -h\
    --help\
    -v\
    --version\
    -l --level\
    --prefix\
    --bin\
    --gems\
    --archive\
    --patch
    -S\
    -e\
    -G\
    -C\
    --configure\
    --nice\
    --ree-options\
    --head\
    --rubygems\
    --default\
    --debug\
    --trace\
    --force\
    --summary\
    --latest\
    --docs\
    --reconfigure
    --create'

  __rvm_comp "$RVM_OPTS"
}

_rvm_use ()
{
  local command="${COMP_WORDS[COMP_CWORD-2]}"

  case "${command}" in
  gemset) __rvm_comp "$(__rvm_gemsets)" ;;
  *)      __rvm_comp "$(__rvm_rubies)" ;;
  esac
}

_rvm_gemset ()
{
  local subcommands="use create"
  local subcommand="$(__rvm_subcommand "$subcommands")"

  if [ -z "$subcommand" ]; then
    __rvm_comp "$subcommands"
    return
  fi
}

_rvm ()
{
  local prev=${COMP_WORDS[COMP_CWORD-1]}

  case "${prev}" in
  use)      _rvm_use ;;
  gemset)   _rvm_gemset ;;
  *)        _rvm_commands ;;
  esac

  return 0
}

complete -o default -o nospace -F _rvm rvm

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rvm-0.1.47 scripts/completion
rvm-0.1.46 scripts/completion
rvm-0.1.45 scripts/completion
rvm-0.1.44 scripts/completion