123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- #!/usr/bin/env bash
- # bash completion for Ruby Version Manager (RVM)
- __rvm_comp()
- {
- \typeset cur
- cur="${COMP_WORDS[COMP_CWORD]}"
- COMPREPLY=($(compgen -W "$1" -- "$cur"))
- return 0
- }
- __rvm_subcommand()
- {
- \typeset word subcommand c
- 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 alias list names)"
- }
- __rvm_gemsets ()
- {
- echo "$(rvm gemset list | __rvm_grep -v gemset 2>/dev/null)"
- }
- __rvm_help_pages ()
- {
- \command \ls "$rvm_help_path"
- }
- __rvm_known ()
- {
- # Strips comments and expands known patterns into each variation
- rvm list known | __rvm_sed -e 's/#.*$//;' \
- -e '/^$/d;' \
- -e 's/^\[\(.*-\)\]\(.*\)\[\(-.*\)\]$/\1\2\3 \1\2 \2\3 \2/;' \
- -e 's/^\[\(.*-\)\]\(.*\)$/\1\2 \2/;' \
- -e 's/^\(.*\)\[\(-.*\)\]\[\(-.*\)\]$/\1\2\3 \1\2 \1/;' \
- -e 's/^\(.*\)\[\(-.*\)\]$/\1\2 \1/ ' # | \command \tr ' ' "\n" | sort
- }
- _rvm_commands ()
- {
- \typeset cur
- cur=${COMP_WORDS[COMP_CWORD]}
- COMMANDS='\
- version use reload implode update reset info debug\
- install uninstall reinstall remove\
- ruby gem rake tests specs monitor gemset\
- gemdir fetch list package notes snapshot\
- help automount disk-usage upgrade current migrate\
- alias autolibs cleanup cron docs get config-get\
- snapshot export fix-permissions repair rubygems\
- tools user info usage rvmrc osx-ssl-certs patchset\
- pkg group requirements do unexport wrapper'
- case "${cur}" in
- -*) _rvm_opts ;;
- *) __rvm_comp "$COMMANDS $(__rvm_rubies)" ;;
- esac
- }
- _rvm_opts ()
- {
- RVM_OPTS='\
- -h\
- --help\
- -v\
- --version\
- -l --level\
- --bin\
- --gems\
- --archive\
- --patch
- -S\
- -e\
- -G\
- -C\
- --configure\
- --nice\
- --ree-options\
- --head\
- --rubygems\
- --default\
- --debug\
- --trace\
- --force\
- --summary\
- --latest\
- --docs\
- --reconfigure\
- --quiet-curl\
- --create'
- __rvm_comp "$RVM_OPTS"
- }
- _rvm_use ()
- {
- \typeset _command
- _command="${COMP_WORDS[COMP_CWORD-2]}"
- case "${_command}" in
- gemset) __rvm_comp "$(__rvm_gemsets)" ;;
- *) __rvm_comp "$(__rvm_rubies)" ;;
- esac
- }
- _rvm_gemset ()
- {
- \typeset subcommand subcommands
- subcommands="import export create copy rename empty delete name dir list list_all gemdir install pristine clear use update unpack globalcache"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_remove ()
- {
- \typeset subcommand subcommands
- subcommands="all old --gems --archive $(__rvm_rubies)"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_disk_usage()
- {
- \typeset subcommand subcommands
- subcommands="all total archives docs repos sources logs pkg rubies gemsets wrappers tmp others"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_list()
- {
- \typeset subcommand subcommands
- subcommands="help known remote gemsets default rubies strings known_strings ruby_svn_tags"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_reinstall()
- {
- \typeset subcommand subcommands
- subcommands="$(rvm list strings)"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_uninstall()
- {
- \typeset subcommand subcommands
- subcommands="$(rvm list strings) --gems"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_upgrade()
- {
- \typeset subcommand subcommands
- subcommands="$(rvm list strings)"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_migrate()
- {
- \typeset subcommand subcommands
- subcommands="$(rvm list strings)"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_autolibs()
- {
- \typeset subcommand subcommands
- subcommands="disable disabled read read-only fail read-fail packages enable enabled reset status help show"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_cleanup()
- {
- \typeset subcommand subcommands
- subcommands="all archives checksums repos sources logs gemsets links"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_cron()
- {
- \typeset subcommand subcommands
- subcommands="setup remove"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_docs()
- {
- \typeset subcommand subcommands
- subcommands="generate generate-ri generate-rdoc generate-gems rdoc_data"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_get()
- {
- \typeset subcommand subcommands
- subcommands="stable latest head master branch help --auto-dotfiles --autolibs="
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_snapshot()
- {
- \typeset subcommand subcommands
- subcommands="load save"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_fix_permissions()
- {
- \typeset subcommand subcommands
- subcommands="user system"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_repair()
- {
- \typeset subcommand subcommands
- subcommands="symlinks environments archives all"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_rubygems()
- {
- \typeset subcommand subcommands
- subcommands="latest current master head"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_tools()
- {
- \typeset subcommand subcommands
- subcommands="identifier path-identifier strings mirror rvm-env"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_user()
- {
- \typeset subcommand subcommands
- subcommands="all gemsets"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_info()
- {
- \typeset subcommand subcommands
- subcommands="$(rvm list strings) system rvm ruby homes binaries environment debug"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_rvmrc()
- {
- \typeset subcommand subcommands
- subcommands="trust untrust trusted load reset create warning"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_osx_ssl_certs()
- {
- \typeset subcommand subcommands
- subcommands="status update cron"
- subcommand="$(__rvm_subcommand "$subcommands")"
- if [[ -z "$subcommand" ]]; then
- __rvm_comp "$subcommands"
- return
- fi
- }
- _rvm_help ()
- {
- __rvm_comp "$(__rvm_help_pages)"
- }
- _rvm_install ()
- {
- __rvm_comp "$(__rvm_known)"
- }
- _rvm ()
- {
- \typeset prev
- prev=${COMP_WORDS[COMP_CWORD-1]}
- case "${prev}" in
- use) _rvm_use ;;
- gemset) _rvm_gemset ;;
- help) _rvm_help ;;
- install) _rvm_install ;;
- autolibs) _rvm_autolibs ;;
- disk-usage) _rvm_disk_usage ;;
- reinstall) _rvm_reinstall ;;
- uninstall) _rvm_uninstall ;;
- upgrade) _rvm_upgrade ;;
- list) _rvm_list ;;
- remove) _rvm_remove ;;
- migrate) _rvm_migrate ;;
- cleanup) _rvm_cleanup ;;
- snapshot) _rvm_snapshot ;;
- cron) _rvm_cron ;;
- fix-permissions) _rvm_fix_permissions ;;
- docs) _rvm_docs ;;
- repair) _rvm_repair ;;
- rubygems) _rvm_rubygems ;;
- get) _rvm_get ;;
- tools) _rvm_tools ;;
- user) _rvm_user ;;
- info) _rvm_info ;;
- rvmrc) _rvm_rvmrc ;;
- osx-ssl-certs) _rvm_osx_ssl_certs ;;
- *) _rvm_commands ;;
- esac
- return 0
- }
|