From 4721cdfdac31e6e519d88a001e24171d135fa344 Mon Sep 17 00:00:00 2001 From: Muhammad Muhammad Ibrahim Date: Fri, 27 Dec 2019 05:40:57 +0200 Subject: [PATCH] Update bundler completion from @mernen --- completion/available/bundler.completion.bash | 247 ++++++++++++++++--- 1 file changed, 218 insertions(+), 29 deletions(-) diff --git a/completion/available/bundler.completion.bash b/completion/available/bundler.completion.bash index cdb7cf54..4ad04bdc 100644 --- a/completion/available/bundler.completion.bash +++ b/completion/available/bundler.completion.bash @@ -1,7 +1,7 @@ #! bash # bash completion for the `bundle` command. # -# Copyright (c) 2011-2013 Daniel Luz . +# Copyright (c) 2011-2017 Daniel Luz . # Distributed under the MIT license. # http://mernen.com/projects/completion-ruby # @@ -9,28 +9,166 @@ # . completion-bundle __bundle() { - local cur=$2 - local prev=$3 - local bundle_command - __bundle_get_command - COMPREPLY=() + local bundle_bin=("${_RUBY_COMMAND_PREFIX[@]}" "$1") + local cur prev + _get_comp_words_by_ref -n : cur prev + local bundle_command + local bundle_command_index + __bundle_get_command + COMPREPLY=() - local options - if [[ $cur = -* ]]; then - options="--no-color --verbose" - if [[ -z $bundle_command ]]; then - options="$options --version --help" - fi - elif [[ $bundle_command = "exec" ]]; then - _bundle_exec_completions - return - else - if [[ -z $bundle_command || $bundle_command = help ]]; then - options="help install update package exec config check list show - console open viz init gem" - fi - fi - COMPREPLY=($(compgen -W "$options" -- "$cur")) + local options + if [[ $cur = -* && $bundle_command != exec ]]; then + options="-V --help --no-color --no-no-color --verbose --no-verbose" + case $bundle_command in + "") + options="$options --version";; + check) + options="$options --dry-run --gemfile --path -r --retry";; + clean) + options="$options --dry-run --force";; + config) + options="$options --local --global --delete";; + doctor) + options="$options --gemfile --quiet --no-quiet";; + gem) + options="$options -b -e -t --bin --coc --no-coc --edit --exe + --no-exe --ext --no-ext --mit --no-mit --test";; + init) + options="$options --gemspec";; + install) + options="$options --binstubs --clean --deployment --force --frozen + --full-index --gemfile --jobs --local --no-cache + --no-prune --path --quiet --retry --shebang --standalone + --system --trust-policy --with --without";; + lock) + options="$options --add-platform --conservative --full-index + --local --lockfile --major --minor --patch --print + --remove-platform --strict --update";; + package) + options="$options --all --all-platforms";; + platform) + options="$options --ruby";; + show) + options="$options --outdated --paths --no-paths";; + update) + options="$options --bundler --conservative --force --full-index + --group --jobs --local --major --minor --patch --quiet + --ruby --source --strict";; + viz) + options="$options -f -F -R -v -W --file --format --requirements + --no-requirements --version --no-version --without";; + esac + else + case $bundle_command in + "" | help) + options="help install update package exec config + check show outdated console open lock viz init gem + platform clean doctor" + ;; + check | install) + case $prev in + --binstubs | --path) + _filedir -d + return;; + --standalone | --with | --without) + __bundle_complete_groups + return;; + --trust-policy) + options="HighSecurity MediumSecurity LowSecurity + AlmostNoSecurity NoSecurity";; + esac + ;; + config) + case $prev in + config | --*) + case $cur in + local.*) + options=($(__bundle_exec_ruby 'puts Bundler.definition.specs.to_hash.keys')) + options=("${options[*]/#/local.}") + ;; + *) + options=(path frozen without bin gemfile ssl_ca_cert + ssl_client_cert cache_path disable_multisource + ignore_messages retry redirect timeout + force_ruby_platform specific_platform + disable_checksum_validation disable_version_check + allow_offline_install auto_install + cache_all_platforms cache_all clean console + disable_exec_load disable_local_branch_check + disable_shared_gems jobs major_deprecations + no_install no_prune only_update_to_newer_versions + plugins shebang silence_root_warning + ssl_verify_mode system_bindir user_agent) + # We want to suggest the options above as complete words, + # and also "local." and "mirror." as prefixes + # To achieve that, disable automatic space insertion, + # insert it manually, then add the non-spaced prefixes + compopt -o nospace + options=("${options[@]/%/ }") + # And add prefix suggestions + options+=(local. mirror.) + # Override $IFS for completion to work + local IFS=$'\n' + COMPREPLY=($(compgen -W '${options[@]}' -- "$cur")) + return + ;; + esac + ;; + path | local.*) + _filedir -d + return;; + esac + ;; + exec) + if [[ $COMP_CWORD -eq $bundle_command_index ]]; then + # Figure out Bundler's binaries dir + local bundler_bin=$(__bundle_exec_ruby 'puts Bundler.bundle_path + "bin"') + if [[ -d $bundler_bin ]]; then + local binaries=("$bundler_bin"/*) + # If there are binaries, strip directory name and use them + [[ -f "$binaries" ]] && options="${binaries[@]##*/}" + else + # No binaries found; use full command completion + COMPREPLY=($(compgen -c -- "$cur")) + return + fi + else + local _RUBY_COMMAND_PREFIX=("${bundle_bin[@]}" exec) + _command_offset $bundle_command_index + return + fi + ;; + gem) + case $prev in + -e | --edit) + COMPREPLY=($(compgen -c -- "$cur")) + return;; + -t | --test) + options="minitest rspec";; + esac + ;; + update) + case $prev in + --group) + __bundle_complete_groups + return;; + *) + options=($(__bundle_exec_ruby 'puts Bundler.definition.specs.to_hash.keys')) + esac + ;; + viz) + case $prev in + -F | --format) + options="dot jpg png svg";; + -W | --without) + __bundle_complete_groups + return;; + esac + ;; + esac + fi + COMPREPLY=($(compgen -W "${options[*]}" -- "$cur")) } __bundle_get_command() { @@ -41,25 +179,76 @@ __bundle_get_command() { case $arg in [^-]*) bundle_command=$arg + bundle_command_index=$((i + 1)) return;; --version) - # command-killer + # Command-killer bundle_command=- return;; --help) bundle_command=help + bundle_command_index=$((i + 1)) return;; esac done } +# Provides completion for Bundler group names. +# +# Multiple groups can be entered, separated either by spaces or by colons. +# Input is read from $cur, and the result is directly written to $COMPREPLY. +__bundle_complete_groups() { + # Group being currently written + local cur_group=${cur##*[ :]} + # All groups written before + local prefix=${cur%"$cur_group"} + local groups=$(__bundle_exec_ruby 'puts Bundler.definition.dependencies.map(&:groups).reduce(:|).map(&:to_s)') + if [[ ! $groups ]]; then + COMPREPLY=() + return + fi + # Duplicate "default" and anything already in $prefix, so that `uniq` + # strips it; groups may be separated by ':', ' ', or '\ ' + local excluded=$'\ndefault\n'${prefix//[: \'\"\\]/$'\n'} + # Include them twice to ensure they are duplicates + groups=$groups$excluded$excluded + COMPREPLY=($(compgen -W "$(sort <<<"$groups" | uniq -u)" -- "$cur_group")) + # Prepend prefix to all entries + COMPREPLY=("${COMPREPLY[@]/#/$prefix}") + __ltrim_colon_completions "$cur" +} -complete -F __bundle -o bashdefault -o default bundle -# vim: ai ft=sh sw=4 sts=2 et +# __bundle_exec_ruby