diff --git a/completion/available/crystal.completion.bash b/completion/available/crystal.completion.bash index 7644ffd4d4..25dd496c01 100644 --- a/completion/available/crystal.completion.bash +++ b/completion/available/crystal.completion.bash @@ -1 +1,2 @@ +# shellcheck shell=bash _log_warning 'Bash completion for "crystal" is now covered by "system". This completion can be disabled.' diff --git a/completion/available/defaults.completion.bash b/completion/available/defaults.completion.bash index 39d7ea95b0..0baee19679 100644 --- a/completion/available/defaults.completion.bash +++ b/completion/available/defaults.completion.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC1090 if test -s "${BASH_IT?}/vendor/github.com/gaelicWizard/bash-progcomp/defaults.completion.bash"; then source "$_" diff --git a/completion/available/drush.completion.bash b/completion/available/drush.completion.bash index 6628c65513..ccee2c3edf 100644 --- a/completion/available/drush.completion.bash +++ b/completion/available/drush.completion.bash @@ -1,2 +1,3 @@ +# shellcheck shell=bash _log_warning 'Bash completion for "drush" is now deprecated, as it used code with incompatible license. Please disable this completion and use the instructions from "drush" developers instead.' diff --git a/completion/available/fabric.completion.bash b/completion/available/fabric.completion.bash index 163a479b80..717fb4badd 100644 --- a/completion/available/fabric.completion.bash +++ b/completion/available/fabric.completion.bash @@ -41,10 +41,10 @@ export FAB_COMPLETION_CACHED_TASKS_FILENAME=".fab_tasks~" # Set command to get time of last file modification as seconds since Epoch case "$OSTYPE" in 'darwin'* | 'freebsd'*) - __FAB_COMPLETION_MTIME_COMMAND="stat -f '%m'" + __FAB_COMPLETION_MTIME_COMMAND=(stat -f '%m') ;; *) - __FAB_COMPLETION_MTIME_COMMAND="stat -c '%Y'" + __FAB_COMPLETION_MTIME_COMMAND=(stat -c '%Y') ;; esac @@ -52,7 +52,7 @@ esac # Get time of last fab cache file modification as seconds since Epoch # function __fab_chache_mtime() { - ${__FAB_COMPLETION_MTIME_COMMAND} \ + "${__FAB_COMPLETION_MTIME_COMMAND[@]}" \ $FAB_COMPLETION_CACHED_TASKS_FILENAME | xargs -n 1 expr } @@ -62,10 +62,11 @@ function __fab_chache_mtime() { function __fab_fabfile_mtime() { local f="fabfile" if [[ -e "$f.py" ]]; then - ${__FAB_COMPLETION_MTIME_COMMAND} "$f.py" | xargs -n 1 expr + "${__FAB_COMPLETION_MTIME_COMMAND[@]}" "$f.py" | xargs -n 1 expr else # Suppose that it's a fabfile dir - find $f/*.py -exec ${__FAB_COMPLETION_MTIME_COMMAND} {} + \ + # shellcheck disable=SC2038 + find "$f"/*.py -exec "${__FAB_COMPLETION_MTIME_COMMAND[@]}" {} + \ | xargs -n 1 expr | sort -n -r | head -1 fi } @@ -79,15 +80,16 @@ function __fab_completion() { # Variables to hold the current word and possible matches local cur="${COMP_WORDS[COMP_CWORD]}" - local opts=() + local opts # Generate possible matches and store them in variable "opts" case "${cur}" in -*) if [[ -z "${__FAB_COMPLETION_LONG_OPT}" ]]; then - export __FAB_COMPLETION_LONG_OPT=$( + __FAB_COMPLETION_LONG_OPT=$( fab --help | grep -E -o "\-\-[A-Za-z_\-]+\=?" | sort -u ) + export __FAB_COMPLETION_LONG_OPT fi opts="${__FAB_COMPLETION_LONG_OPT}" ;; @@ -124,6 +126,7 @@ function __fab_completion() { esac # Set possible completions - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + COMPREPLY=() + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${opts}" -- "${cur}") } complete -o default -o nospace -F __fab_completion fab diff --git a/completion/available/gradle.completion.bash b/completion/available/gradle.completion.bash index cedf15dc71..9b9072c17d 100644 --- a/completion/available/gradle.completion.bash +++ b/completion/available/gradle.completion.bash @@ -22,7 +22,7 @@ # Bash breaks words on : by default. Subproject tasks have ':' # Avoid inaccurate completions for subproject tasks -COMP_WORDBREAKS=$(echo "$COMP_WORDBREAKS" | sed -e 's/://g') +COMP_WORDBREAKS="${COMP_WORDBREAKS//:/}" function __gradle-set-project-root-dir() { project_root_dir="$(_bash-it-find-in-ancestor "settings.gradle" "gradlew")" @@ -31,7 +31,7 @@ function __gradle-set-project-root-dir() { __gradle-init-cache-dir() { cache_dir="$HOME/.gradle/completion" - mkdir -p $cache_dir + mkdir -p "$cache_dir" } __gradle-set-build-file() { @@ -39,7 +39,8 @@ __gradle-set-build-file() { # Otherwise, default is the file 'build.gradle' in the current directory. gradle_build_file="$project_root_dir/build.gradle" if [[ -f "$project_root_dir/settings.gradle" ]]; then - local build_file_name=$(grep "^rootProject\.buildFileName" "$project_root_dir/settings.gradle" \ + local build_file_name + build_file_name=$(grep "^rootProject\.buildFileName" "$project_root_dir/settings.gradle" \ | sed -n -e "s/rootProject\.buildFileName = [\'\"]\(.*\)[\'\"]/\1/p") gradle_build_file="$project_root_dir/${build_file_name:-build.gradle}" fi @@ -47,15 +48,15 @@ __gradle-set-build-file() { __gradle-set-cache-name() { # Cache name is constructed from the absolute path of the build file. - cache_name=$(echo $gradle_build_file | sed -e 's/\//_/g') + cache_name=${gradle_build_file//'/'/_} } __gradle-set-files-checksum() { # Cache MD5 sum of all Gradle scripts and modified timestamps if _command_exists md5; then - gradle_files_checksum=$(md5 -q -s "$(cat "$cache_dir/$cache_name" | xargs ls -o 2> /dev/null)") + gradle_files_checksum=$(md5 -q -s "$(xargs ls -o < "$cache_dir/$cache_name" 2> /dev/null)") elif _command_exists md5sum; then - gradle_files_checksum=$(cat "$cache_dir/$cache_name" | xargs ls -o 2> /dev/null | md5sum | awk '{print $1}') + gradle_files_checksum=$(xargs ls -o < "$cache_dir/$cache_name" 2> /dev/null | md5sum | awk '{print $1}') else echo "Cannot generate completions as neither md5 nor md5sum exist on \$PATH" fi @@ -66,10 +67,15 @@ __gradle-generate-script-cache() { local cache_ttl_mins=${GRADLE_CACHE_TTL_MINUTES:-30240} local script_exclude_pattern=${GRADLE_COMPLETION_EXCLUDE_PATTERN:-"/(build|integTest|out)/"} - if [[ ! $(find $cache_dir/$cache_name -mmin -$cache_ttl_mins 2> /dev/null) ]]; then + if [[ ! $(find "$cache_dir/$cache_name" -mmin "-$cache_ttl_mins" 2> /dev/null) ]]; then # Cache all Gradle scripts - local gradle_build_scripts=$(find $project_root_dir -type f -name "*.gradle" -o -name "*.gradle.kts" 2> /dev/null | grep -E -v "$script_exclude_pattern") - printf "%s\n" "${gradle_build_scripts[@]}" > $cache_dir/$cache_name + local gradle_build_scripts + gradle_build_scripts=$( + find "$project_root_dir" -type f \ + \( -name "*.gradle" -o -name "*.gradle.kts" \) 2> /dev/null \ + | grep -E -v "$script_exclude_pattern" + ) + printf "%s\n" "${gradle_build_scripts[@]}" > "$cache_dir/$cache_name" fi } @@ -115,7 +121,10 @@ __gradle-long-options() { --system-prop - Set a system property --version - Prints Gradle version info --warn - Log warnings and errors only" - COMPREPLY=($(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}")) + COMPREPLY=() + while IFS='' read -r line; do + COMPREPLY+=("$line") + done < <(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}") } __gradle-properties() { @@ -130,7 +139,10 @@ __gradle-properties() { -Dorg.gradle.parallel= - Set true to enable parallel project builds (incubating) -Dorg.gradle.parallel.intra= - Set true to enable intra-project parallel builds (incubating) -Dorg.gradle.workers.max= - Set the number of workers Gradle is allowed to use" - COMPREPLY=($(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}")) + COMPREPLY=() + while IFS='' read -r line; do + COMPREPLY+=("$line") + done < <(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}") return 0 } @@ -156,7 +168,8 @@ __gradle-short-options() { -I - Specifies an initialization script -P - Sets a project property of the root project -S - Print out the full (very verbose) stacktrace" - COMPREPLY=($(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}")) + COMPREPLY=() + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}") } __gradle-notify-tasks-cache-build() { @@ -179,10 +192,10 @@ __gradle-generate-tasks-cache() { # Run gradle to retrieve possible tasks and cache. # Reuse Gradle Daemon if IDLE but don't start a new one. local gradle_tasks_output - if [[ ! -z "$($gradle_cmd --status 2> /dev/null | grep IDLE)" ]]; then - gradle_tasks_output="$($gradle_cmd -b $gradle_build_file --daemon -q tasks --all)" + if "$gradle_cmd" --status 2> /dev/null | grep -q IDLE; then + gradle_tasks_output="$("$gradle_cmd" -b "$gradle_build_file" --daemon -q tasks --all)" else - gradle_tasks_output="$($gradle_cmd -b $gradle_build_file --no-daemon -q tasks --all)" + gradle_tasks_output="$("$gradle_cmd" -b "$gradle_build_file" --no-daemon -q tasks --all)" fi local output_line local task_description @@ -206,15 +219,18 @@ __gradle-generate-tasks-cache() { # subproject tasks can be referenced implicitly from root project if [[ $GRADLE_COMPLETION_UNQUALIFIED_TASKS == "true" ]]; then - local -a implicit_tasks=() - implicit_tasks=($(comm -23 <(printf "%s\n" "${subproject_tasks[@]}" | sort) <(printf "%s\n" "${root_tasks[@]}" | sort))) - for task in $(printf "%s\n" "${implicit_tasks[@]}"); do - gradle_all_tasks+=($task) + local -a implicit_tasks + while IFS='' read -r line; do + implicit_tasks+=("$line") + done < <(comm -23 <(printf "%s\n" "${subproject_tasks[@]}" | sort) \ + <(printf "%s\n" "${root_tasks[@]}" | sort)) + for task in "${implicit_tasks[@]}"; do + gradle_all_tasks+=("$task") done fi - printf "%s\n" "${gradle_all_tasks[@]}" > $cache_dir/$gradle_files_checksum - echo $gradle_files_checksum > $cache_dir/$cache_name.md5 + printf "%s\n" "${gradle_all_tasks[@]}" > "$cache_dir/$gradle_files_checksum" + echo "$gradle_files_checksum" > "$cache_dir/$cache_name.md5" } __gradle-completion-init() { @@ -262,22 +278,30 @@ _gradle() { __gradle-set-files-checksum # The cache key is md5 sum of all gradle scripts, so it's valid if it exists. - if [[ -f $cache_dir/$cache_name.md5 ]]; then - local cached_checksum="$(cat $cache_dir/$cache_name.md5)" + if [[ -f "$cache_dir/$cache_name.md5" ]]; then + local cached_checksum + cached_checksum="$(cat "$cache_dir/$cache_name.md5")" local -a cached_tasks if [[ -z $cur ]]; then - cached_tasks=($(cat $cache_dir/$cached_checksum)) + while IFS='' read -r line; do + cached_tasks+=("$line") + done < "$cache_dir/$cached_checksum" else - cached_tasks=($(grep "^$cur" $cache_dir/$cached_checksum)) + while IFS='' read -r line; do + cached_tasks+=("$line") + done < <(grep "^$cur" "$cache_dir/$cached_checksum") fi - COMPREPLY=($(compgen -W "${cached_tasks[*]}" -- "$cur")) + while IFS='' read -r line; do + COMPREPLY+=("$line") + done < <(compgen -W "${cached_tasks[*]}" -- "$cur") else __gradle-notify-tasks-cache-build fi # Regenerate tasks cache in the background - if [[ $gradle_files_checksum != "$(cat $cache_dir/$cache_name.md5)" || ! -f $cache_dir/$gradle_files_checksum ]]; then - $(__gradle-generate-tasks-cache 1>&2 2> /dev/null &) + if [[ $gradle_files_checksum != "$(cat "$cache_dir/$cache_name.md5")" || + ! -f "$cache_dir/$gradle_files_checksum" ]]; then + (__gradle-generate-tasks-cache &> /dev/null &) fi else # Default tasks available outside Gradle projects @@ -293,7 +317,10 @@ projects - Displays the sub-projects of root project. properties - Displays the properties of root project. tasks - Displays the tasks runnable from root project. wrapper - Generates Gradle wrapper files." - COMPREPLY=($(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}")) + COMPREPLY=() + while IFS='' read -r line; do + COMPREPLY+=("$line") + done < <(compgen -W "${args}" -- "${cur}") fi fi @@ -301,7 +328,7 @@ wrapper - Generates Gradle wrapper files." # Remove description ("[:space:]" and after) if only one possibility if [[ ${#COMPREPLY[*]} -eq 1 ]]; then - COMPREPLY=(${COMPREPLY[0]%% *}) + COMPREPLY=("${COMPREPLY[0]%% *}") fi return 0 diff --git a/completion/available/homesick.completion.bash b/completion/available/homesick.completion.bash index ed6f6e79ed..41ab67f146 100644 --- a/completion/available/homesick.completion.bash +++ b/completion/available/homesick.completion.bash @@ -1,2 +1,3 @@ +# shellcheck shell=bash _log_warning 'Bash completion for "homesick" is now deprecated, as it used unlicensed code. Please disable this completion and use the instructions from "homesick" bash completion developers instead.' diff --git a/completion/available/maven.completion.bash b/completion/available/maven.completion.bash index 54c28c4d2a..780fed3161 100644 --- a/completion/available/maven.completion.bash +++ b/completion/available/maven.completion.bash @@ -28,7 +28,7 @@ _mvn() { COMPREPLY=($(compgen -W "$cmds" -- "$cur")) local i=${#COMPREPLY[*]} while [ "$((--i))" -ge 0 ]; do - COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"} + COMPREPLY[i]=${COMPREPLY[i]#"$colonprefixes"} done return 0 diff --git a/completion/available/minishift.completion.bash b/completion/available/minishift.completion.bash index 5679eae80f..c48f84b1bd 100644 --- a/completion/available/minishift.completion.bash +++ b/completion/available/minishift.completion.bash @@ -1 +1,3 @@ +# shellcheck shell=bash +# shellcheck disable=SC1090 _command_exists minishift && source <(minishift completion bash) diff --git a/completion/available/openshift.completion.bash b/completion/available/openshift.completion.bash index 1e7b681506..c0f525b868 100644 --- a/completion/available/openshift.completion.bash +++ b/completion/available/openshift.completion.bash @@ -1 +1,3 @@ +# shellcheck shell=bash +# shellcheck disable=SC1090 _command_exists oc && source <(oc completion bash) diff --git a/completion/available/pew.completion.bash b/completion/available/pew.completion.bash index 24b133f9db..3b203d4c16 100644 --- a/completion/available/pew.completion.bash +++ b/completion/available/pew.completion.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC1090 if _command_exists pew; then source "$(pew shell_config)" diff --git a/completion/available/rvm.completion.bash b/completion/available/rvm.completion.bash index cd8ded0468..11530e4295 100644 --- a/completion/available/rvm.completion.bash +++ b/completion/available/rvm.completion.bash @@ -1,5 +1,6 @@ -#!/usr/bin/env bash -# Bash completion support for RVM. +# shellcheck shell=bash +# shellcheck disable=SC2154,SC1091 +# Bash completion support for RVM. # Source: https://rvm.io/workflow/completion -[[ -r $rvm_path/scripts/completion ]] && . $rvm_path/scripts/completion +[[ -r $rvm_path/scripts/completion ]] && . "$rvm_path/scripts/completion" diff --git a/completion/available/todo.completion.bash b/completion/available/todo.completion.bash index b5517d8654..7281a7e893 100644 --- a/completion/available/todo.completion.bash +++ b/completion/available/todo.completion.bash @@ -1,2 +1,3 @@ +# shellcheck shell=bash _log_warning 'Bash completion for "todo.txt-cli" is now deprecated, as it used code with incompatible license. Please disable this completion and use the instructions from "todo.txt-cli" developers instead.' diff --git a/completion/available/travis.completion.bash b/completion/available/travis.completion.bash index f533cde037..4df1fa2b3b 100644 --- a/completion/available/travis.completion.bash +++ b/completion/available/travis.completion.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC1090 if _command_exists travis; then if [[ -s "${__TRAVIS_COMPLETION_SCRIPT:=${TRAVIS_CONFIG_PATH:-${HOME}/.travis}/travis.sh}" ]]; then diff --git a/completion/available/vagrant.completion.bash b/completion/available/vagrant.completion.bash index 31a4ae1369..aadc18ab7e 100644 --- a/completion/available/vagrant.completion.bash +++ b/completion/available/vagrant.completion.bash @@ -1,4 +1,4 @@ -#!/bin/bash +# shellcheck shell=bash # (The MIT License) # @@ -26,21 +26,21 @@ __pwdln() { pwdmod="${PWD}/" itr=0 until [[ -z "$pwdmod" ]]; do - itr=$(($itr + 1)) + itr=$((itr + 1)) pwdmod="${pwdmod#*/}" done - echo -n $(($itr - 1)) + echo -n $((itr - 1)) } __vagrantinvestigate() { - if [ -f "${PWD}/.vagrant" -o -d "${PWD}/.vagrant" ]; then + if [ -f "${PWD}/.vagrant" ] || [ -d "${PWD}/.vagrant" ]; then echo "${PWD}/.vagrant" return 0 else pwdmod2="${PWD}" for ((i = 2; i <= $(__pwdln); i++)); do pwdmod2="${pwdmod2%/*}" - if [ -f "${pwdmod2}/.vagrant" -o -d "${pwdmod2}/.vagrant" ]; then + if [ -f "${pwdmod2}/.vagrant" ] || [ -d "${pwdmod2}/.vagrant" ]; then echo "${pwdmod2}/.vagrant" return 0 fi @@ -54,74 +54,86 @@ _vagrant() { prev="${COMP_WORDS[COMP_CWORD - 1]}" commands="box cloud destroy global-status halt help hostmanager init login package plugin port powershell provision push rdp reload resume scp snapshot ssh ssh-config status suspend up upload validate vbguest version winrm winrm-config" - if [ $COMP_CWORD == 1 ]; then - COMPREPLY=($(compgen -W "${commands}" -- ${cur})) + if ((COMP_CWORD == 1)); then + COMPREPLY=() + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${commands}" -- "${cur}") return 0 fi - if [ $COMP_CWORD == 2 ]; then + if ((COMP_CWORD == 2)); then case "$prev" in "init") - local box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sed -e 's/-VAGRANTSLASH-/\//') - COMPREPLY=($(compgen -W "${box_list}" -- ${cur})) + local box_list + box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sed -e 's/-VAGRANTSLASH-/\//') + COMPREPLY=() + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${box_list}" -- "${cur}") return 0 ;; "up") vagrant_state_file=$(__vagrantinvestigate) || return 1 if [[ -d $vagrant_state_file ]]; then - vm_list=$(find $vagrant_state_file/machines -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) + vm_list=$(find "$vagrant_state_file/machines" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) fi local up_commands="--no-provision" - COMPREPLY=($(compgen -W "${up_commands} ${vm_list}" -- ${cur})) + COMPREPLY=() + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${up_commands} ${vm_list}" -- "${cur}") return 0 ;; "ssh" | "provision" | "reload" | "halt" | "suspend" | "resume" | "ssh-config") vagrant_state_file=$(__vagrantinvestigate) || return 1 if [[ -f $vagrant_state_file ]]; then - running_vm_list=$(grep 'active' $vagrant_state_file | sed -e 's/"active"://' | tr ',' '\n' | cut -d '"' -f 2 | tr '\n' ' ') + running_vm_list=$(grep 'active' "$vagrant_state_file" | sed -e 's/"active"://' | tr ',' '\n' | cut -d '"' -f 2 | tr '\n' ' ') else - running_vm_list=$(find $vagrant_state_file -type f -name "id" | awk -F"/" '{print $(NF-2)}') + running_vm_list=$(find "$vagrant_state_file" -type f -name "id" | awk -F"/" '{print $(NF-2)}') fi - COMPREPLY=($(compgen -W "${running_vm_list}" -- ${cur})) + COMPREPLY=() + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${running_vm_list}" -- "${cur}") return 0 ;; "box") box_commands="add list outdated prune remove repackage update" - COMPREPLY=($(compgen -W "${box_commands}" -- ${cur})) + COMPREPLY=() + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${box_commands}" -- "${cur}") return 0 ;; "plugin") plugin_commands="expunge install license list repair uninstall update" - COMPREPLY=($(compgen -W "${plugin_commands}" -- ${cur})) + COMPREPLY=() + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${plugin_commands}" -- "${cur}") return 0 ;; "help") - COMPREPLY=($(compgen -W "${commands}" -- ${cur})) + COMPREPLY=() + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${commands}" -- "${cur}") return 0 ;; "snapshot") snapshot_commands="delete list pop push restore save" - COMPREPLY=($(compgen -W "${snapshot_commands}" -- ${cur})) + COMPREPLY=() + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${snapshot_commands}" -- "${cur}") return 0 ;; *) ;; esac fi - if [ $COMP_CWORD == 3 ]; then + if ((COMP_CWORD == 3)); then action="${COMP_WORDS[COMP_CWORD - 2]}" case "$action" in "up") if [ "$prev" == "--no-provision" ]; then - COMPREPLY=($(compgen -W "${vm_list}" -- ${cur})) + COMPREPLY=() + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${vm_list}" -- "${cur}") return 0 fi ;; "box") case "$prev" in "remove" | "repackage") - local box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sed -e 's/-VAGRANTSLASH-/\//') - COMPREPLY=($(compgen -W "${box_list}" -- ${cur})) + local box_list + box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sed -e 's/-VAGRANTSLASH-/\//') + COMPREPLY=() + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${box_list}" -- "${cur}") return 0 ;; *) ;; @@ -129,21 +141,24 @@ _vagrant() { ;; "snapshot") if [ "$prev" == "restore" ]; then - COMPREPLY=($(compgen -W "${vm_list}" -- ${cur})) + COMPREPLY=() + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${vm_list}" -- "${cur}") return 0 fi ;; esac fi - if [ $COMP_CWORD == 4 ]; then + if ((COMP_CWORD == 4)); then action="${COMP_WORDS[COMP_CWORD - 3]}" prev="${COMP_WORDS[COMP_CWORD - 2]}" case "$action" in "snapshot") if [ "$prev" == "restore" ]; then - local snapshot_list="$(vagrant snapshot list ${cur} 2> /dev/null | awk '{ORS=" "} /==>/ {next} {print}')" - COMPREPLY=($(compgen -W "${snapshot_list}" -- ${cur})) + local snapshot_list + snapshot_list="$(vagrant snapshot list "${cur}" 2> /dev/null | awk '{ORS=" "} /==>/ {next} {print}')" + COMPREPLY=() + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${snapshot_list}" -- "${cur}") return 0 fi ;; diff --git a/completion/available/virsh.completion.bash b/completion/available/virsh.completion.bash index 6450b4a305..beab7f0b3c 100644 --- a/completion/available/virsh.completion.bash +++ b/completion/available/virsh.completion.bash @@ -1,2 +1,3 @@ +# shellcheck shell=bash _log_warning 'Bash completion for "virsh" is now deprecated, as it used code with incompatible license. Please disable this completion and use the instructions from "virsh" developers instead.'