diff --git a/clean_files.txt b/clean_files.txt index e4df08f826..88fbd3e648 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -39,6 +39,7 @@ completion/available/awless.completion.bash completion/available/awscli.completion.bash completion/available/bash-it.completion.bash completion/available/brew.completion.bash +completion/available/bundler.completion.bash completion/available/cargo.completion.bash completion/available/composer.completion.bash completion/available/conda.completion.bash diff --git a/completion/available/bundler.completion.bash b/completion/available/bundler.completion.bash index 663a26d2d8..1aaa56811b 100644 --- a/completion/available/bundler.completion.bash +++ b/completion/available/bundler.completion.bash @@ -1,4 +1,5 @@ -#! bash +# shellcheck shell=bash +# shellcheck disable=SC2207 # bash completion for the `bundle` command. # # Copyright (c) 2008 Daniel Luz @@ -28,188 +29,218 @@ # . completion-bundle __bundle() { - 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 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 = -* && $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 + 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 + --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 + --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 + --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")) + ;; + 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' + # shellcheck disable=SC2016 + 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 + bundler_bin=$(__bundle_exec_ruby 'puts Bundler.bundle_path + "bin"') + if [[ -d $bundler_bin ]]; then + local binaries + binaries=("$bundler_bin"/*) + # If there are binaries, strip directory name and use them + [[ -f "${binaries[0]}" ]] && 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() { - local i - for ((i=1; i < $COMP_CWORD; ++i)); do - local arg=${COMP_WORDS[$i]} + local i + for ((i = 1; i < COMP_CWORD; ++i)); do + local arg=${COMP_WORDS[$i]} - case $arg in - [^-]*) - bundle_command=$arg - bundle_command_index=$((i + 1)) - return;; - --version) - # Command-killer - bundle_command=- - return;; - --help) - bundle_command=help - bundle_command_index=$((i + 1)) - return;; - esac - done + case $arg in + [^-]*) + bundle_command=$arg + bundle_command_index=$((i + 1)) + return + ;; + --version) + # Command-killer + bundle_command=- + return + ;; + --help) + bundle_command=help + bundle_command_index=$((i + 1)) + return + ;; + esac + done } # Provides completion for Bundler group names. @@ -217,24 +248,25 @@ __bundle_get_command() { # 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" + # Group being currently written + local cur_group=${cur##*[ :]} + # All groups written before + local prefix=${cur%"$cur_group"} + local groups + 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" } # __bundle_exec_ruby