diff --git a/clean_files.txt b/clean_files.txt index b9ee5c646a..bc29c62ded 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -17,6 +17,7 @@ # root directories # aliases/ +completions/ docs/ hooks/ lib/ @@ -32,62 +33,6 @@ clean_files.txt install.sh lint_clean_files.sh -# completions -# -completion/available/aliases.completion.bash -completion/available/apm.completion.bash -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/capistrano.completion.bash -completion/available/cargo.completion.bash -completion/available/composer.completion.bash -completion/available/conda.completion.bash -completion/available/consul.completion.bash -completion/available/dart.completion.bash -completion/available/dirs.completion.bash -completion/available/django.completion.bash -completion/available/dmidecode.completion.bash -completion/available/docker-compose.completion.bash -completion/available/docker-machine.completion.bash -completion/available/docker.completion.bash -completion/available/dotnet.completion.bash -completion/available/export.completion.bash -completion/available/flutter.completion.bash -completion/available/gcloud.completion.bash -completion/available/gem.completion.bash -completion/available/git.completion.bash -completion/available/github-cli.completion.bash -completion/available/go.completion.bash -completion/available/helm.completion.bash -completion/available/jboss5.completion.bash -completion/available/jboss7.completion.bash -completion/available/jungle.completion.bash -completion/available/knife.completion.bash -completion/available/kontena.completion.bash -completion/available/kubectl.completion.bash -completion/available/laravel.completion.bash -completion/available/lerna.completion.bash -completion/available/minikube.completion.bash -completion/available/ngrok.completion.bash -completion/available/notify-send.completion.bash -completion/available/npm.completion.bash -completion/available/packer.completion.bash -completion/available/pip.completion.bash -completion/available/pip3.completion.bash -completion/available/pipenv.completion.bash -completion/available/pipx.completion.bash -completion/available/rustup.completion.bash -completion/available/salt.completion.bash -completion/available/sdkman.completion.bash -completion/available/system.completion.bash -completion/available/vault.completion.bash -completion/available/vuejs.completion.bash -completion/available/wpscan.completion.bash -completion/available/yarn.completion.bash - # themes # themes/90210 diff --git a/completion/available/git_flow.completion.bash b/completion/available/git_flow.completion.bash index a715cca4d9..e0c2156539 100644 --- a/completion/available/git_flow.completion.bash +++ b/completion/available/git_flow.completion.bash @@ -1,4 +1,4 @@ -#!bash +# shellcheck shell=bash # # git-flow-completion # =================== @@ -46,8 +46,9 @@ # Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/) _git_flow() { - local subcommands="init feature release hotfix" - local subcommand="$(__git_find_subcommand "$subcommands")" + local subcommands subcommand + subcommands="init feature release hotfix" + subcommand="$(__git_find_subcommand "$subcommands")" if [ -z "$subcommand" ]; then __gitcomp "$subcommands" return @@ -73,8 +74,9 @@ _git_flow() { } __git_flow_feature() { - local subcommands="list start finish publish track diff rebase checkout pull" - local subcommand="$(__git_find_subcommand "$subcommands")" + local subcommands subcommand + subcommands="list start finish publish track diff rebase checkout pull" + subcommand="$(__git_find_subcommand "$subcommands")" if [ -z "$subcommand" ]; then __gitcomp "$subcommands" return @@ -116,8 +118,9 @@ __git_flow_feature_prefix() { } __git_flow_release() { - local subcommands="list start finish" - local subcommand="$(__git_find_subcommand "$subcommands")" + local subcommands subcommand + subcommands="list start finish" + subcommand="$(__git_find_subcommand "$subcommands")" if [ -z "$subcommand" ]; then __gitcomp "$subcommands" return @@ -140,8 +143,9 @@ __git_flow_list_releases() { } __git_flow_hotfix() { - local subcommands="list start finish" - local subcommand="$(__git_find_subcommand "$subcommands")" + local subcommands subcommand + subcommands="list start finish" + subcommand="$(__git_find_subcommand "$subcommands")" if [ -z "$subcommand" ]; then __gitcomp "$subcommands" return diff --git a/completion/available/git_flow_avh.completion.bash b/completion/available/git_flow_avh.completion.bash index ce4a7db3e4..f1d4d19852 100644 --- a/completion/available/git_flow_avh.completion.bash +++ b/completion/available/git_flow_avh.completion.bash @@ -1,4 +1,5 @@ -#!bash +# shellcheck shell=bash +# shellcheck disable=SC2154,SC2030,SC2031 # # git-flow-completion # =================== @@ -54,8 +55,9 @@ __git_flow_config_file_options=" " _git_flow() { - local subcommands="init feature release hotfix support help version config finish delete publish rebase" - local subcommand="$(__git_find_on_cmdline "$subcommands")" + local subcommands subcommand + subcommands="init feature release hotfix support help version config finish delete publish rebase" + subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then __gitcomp "$subcommands" return @@ -93,8 +95,9 @@ _git_flow() { } __git_flow_init() { - local subcommands="help" - local subcommand="$(__git_find_on_cmdline "$subcommands")" + local subcommands subcommand + subcommands="help" + subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then __gitcomp "$subcommands" fi @@ -112,8 +115,9 @@ __git_flow_init() { } __git_flow_feature() { - local subcommands="list start finish publish track diff rebase checkout pull help delete" - local subcommand="$(__git_find_on_cmdline "$subcommands")" + local subcommands subcommand + subcommands="list start finish publish track diff rebase checkout pull help delete" + subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then __gitcomp "$subcommands" @@ -194,8 +198,9 @@ __git_flow_feature() { } __git_flow_release() { - local subcommands="list start finish track publish help delete" - local subcommand="$(__git_find_on_cmdline "$subcommands")" + local subcommands subcommand + subcommands="list start finish track publish help delete" + subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then __gitcomp "$subcommands" return @@ -279,8 +284,9 @@ __git_flow_release() { } __git_flow_hotfix() { - local subcommands="list start finish track publish help delete" - local subcommand="$(__git_find_on_cmdline "$subcommands")" + local subcommands subcommand + subcommands="list start finish track publish help delete" + subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then __gitcomp "$subcommands" return @@ -362,8 +368,9 @@ __git_flow_hotfix() { } __git_flow_support() { - local subcommands="list start help" - local subcommand="$(__git_find_on_cmdline "$subcommands")" + local subcommands subcommand + subcommands="list start help" + subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then __gitcomp "$subcommands" return @@ -401,8 +408,9 @@ __git_flow_support() { } __git_flow_config() { - local subcommands="list set base" - local subcommand="$(__git_find_on_cmdline "$subcommands")" + local subcommands subcommand + subcommands="list set base" + subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then __gitcomp "$subcommands" return @@ -454,11 +462,12 @@ __git_flow_prefix() { __git_flow_list_local_branches() { if [ -n "$1" ]; then - local prefix="$(__git_flow_prefix $1)" - git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix \ + local prefix + prefix="$(__git_flow_prefix "$1")" + git for-each-ref --shell --format="ref=%(refname:short)" "refs/heads/$prefix" \ | while read -r entry; do eval "$entry" - ref="${ref#$prefix}" + ref="${ref#"$prefix"}" echo "$ref" done | sort else @@ -468,28 +477,30 @@ __git_flow_list_local_branches() { } __git_flow_list_remote_branches() { - local prefix="$(__git_flow_prefix $1)" - local origin="$(git config gitflow.origin 2> /dev/null || echo "origin")" - git for-each-ref --shell --format='%(refname:short)' refs/remotes/$origin/$prefix \ + local prefix origin + prefix="$(__git_flow_prefix "$1")" + origin="$(git config gitflow.origin 2> /dev/null || echo "origin")" + git for-each-ref --shell --format='ref=%refname:short)' "refs/remotes/$origin/$prefix" \ | while read -r entry; do eval "$entry" - ref="${ref##$prefix}" + ref="${ref##"$prefix"}" echo "$ref" done | sort } __git_flow_list_branches() { - local origin="$(git config gitflow.origin 2> /dev/null || echo "origin")" + local origin prefix + origin="$(git config gitflow.origin 2> /dev/null || echo "origin")" if [ -n "$1" ]; then - local prefix="$(__git_flow_prefix $1)" - git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix refs/remotes/$origin/$prefix \ + prefix="$(__git_flow_prefix "$1")" + git for-each-ref --shell --format="ref=%(refname:short)" "refs/heads/$prefix" "refs/remotes/$origin/$prefix" \ | while read -r entry; do eval "$entry" - ref="${ref##$prefix}" + ref="${ref##"$prefix"}" echo "$ref" done | sort else - git for-each-ref --format="%(refname:short)" refs/heads/ refs/remotes/$origin | sort + git for-each-ref --format="%(refname:short)" refs/heads/ "refs/remotes/$origin" | sort fi } diff --git a/completion/available/grunt.completion.bash b/completion/available/grunt.completion.bash index 41399e72bf..af630f8569 100644 --- a/completion/available/grunt.completion.bash +++ b/completion/available/grunt.completion.bash @@ -1,4 +1,4 @@ -#!/bin/bash +# shellcheck shell=bash # grunt-cli # http://gruntjs.com/ @@ -57,19 +57,21 @@ function _grunt_gruntfile() { # Enable bash autocompletion. function _grunt_completions() { + local cur gruntfile gruntinfo opts compls line # The currently-being-completed word. - local cur="${COMP_WORDS[COMP_CWORD]}" + cur="${COMP_WORDS[COMP_CWORD]}" # The current gruntfile, if it exists. - local gruntfile="$(_grunt_gruntfile)" + gruntfile="$(_grunt_gruntfile)" # The current grunt version, available tasks, options, etc. - local gruntinfo="$(grunt --version --verbose 2> /dev/null)" + gruntinfo="$(grunt --version --verbose 2> /dev/null)" # Options and tasks. - local opts="$(echo "$gruntinfo" | awk '/Available options: / {$1=$2=""; print $0}')" - local compls="$(echo "$gruntinfo" | awk '/Available tasks: / {$1=$2=""; print $0}')" + opts="$(echo "$gruntinfo" | awk '/Available options: / {$1=$2=""; print $0}')" + compls="$(echo "$gruntinfo" | awk '/Available tasks: / {$1=$2=""; print $0}')" # Only add -- or - options if the user has started typing - [[ "$cur" == -* ]] && compls="$compls $opts" # Tell complete what stuff to show. - COMPREPLY=($(compgen -W "$compls" -- "$cur")) + + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "$compls" -- "$cur") } complete -o default -F _grunt_completions grunt diff --git a/completion/available/gulp.completion.bash b/completion/available/gulp.completion.bash index 63a2fa3d66..e0e673328a 100644 --- a/completion/available/gulp.completion.bash +++ b/completion/available/gulp.completion.bash @@ -1,4 +1,4 @@ -#!/bin/bash +# shellcheck shell=bash # Borrowed from grunt-cli # http://gruntjs.com/ # @@ -43,8 +43,9 @@ function _gulp_completions() { # The currently-being-completed word. local cur="${COMP_WORDS[COMP_CWORD]}" #Grab tasks - local compls=$(gulp --tasks-simple) + local line compls + compls=$(gulp --tasks-simple) # Tell complete what stuff to show. - COMPREPLY=($(compgen -W "$compls" -- "$cur")) + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "$compls" -- "$cur") } complete -o default -F _gulp_completions gulp diff --git a/completion/available/hub.completion.bash b/completion/available/hub.completion.bash index b607fdd1d7..f730274320 100644 --- a/completion/available/hub.completion.bash +++ b/completion/available/hub.completion.bash @@ -1,3 +1,5 @@ +# shellcheck shell=bash +# shellcheck disable=SC2154,SC2120 # hub tab-completion script for bash. # This script complements the completion script that ships with git. @@ -62,7 +64,7 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # hub alias [-s] [SHELL] _git_alias() { local i c=2 s=-s sh shells="bash zsh sh ksh csh fish" - while [ $c -lt $cword ]; do + while [[ $c -lt $cword ]]; do i="${words[c]}" case "$i" in -s) @@ -70,7 +72,7 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then ;; *) for sh in $shells; do - if [ "$sh" = "$i" ]; then + if [[ "$sh" = "$i" ]]; then unset shells break fi @@ -84,19 +86,19 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # hub browse [-u] [--|[USER/]REPOSITORY] [SUBPAGE] _git_browse() { - local i c=2 u=-u repo subpage - local subpages_="commits issues tree wiki pulls branches stargazers + local i c=2 u=-u repo subpage subpages_ + subpages_="commits issues tree wiki pulls branches stargazers contributors network network/ graphs graphs/" - local subpages_network="members" - local subpages_graphs="commit-activity code-frequency punch-card" - while [ $c -lt $cword ]; do + #local subpages_network="members" + #local subpages_graphs="commit-activity code-frequency punch-card" + while [[ $c -lt $cword ]]; do i="${words[c]}" case "$i" in -u) unset u ;; *) - if [ -z "$repo" ]; then + if [[ -z "$repo" ]]; then repo=$i else subpage=$i @@ -105,9 +107,9 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then esac ((c++)) done - if [ -z "$repo" ]; then + if [[ -z "$repo" ]]; then __gitcomp "$u -- $(__hub_github_repos '\p')" - elif [ -z "$subpage" ]; then + elif [[ -z "$subpage" ]]; then case "$cur" in */*) local pfx="${cur%/*}" cur_="${cur#*/}" @@ -126,14 +128,14 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # hub compare [-u] [USER[/REPOSITORY]] [[START...]END] _git_compare() { local i c=$((cword - 1)) u=-u user remote owner repo arg_repo rev - while [ $c -gt 1 ]; do + while [[ $c -gt 1 ]]; do i="${words[c]}" case "$i" in -u) unset u ;; *) - if [ -z "$rev" ]; then + if [[ -z "$rev" ]]; then # Even though the logic below is able to complete both user/repo # and revision in the right place, when there is only one argument # (other than -u) in the command, that argument will be taken as @@ -145,7 +147,7 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then else rev=$i fi - elif [ -z "$arg_repo" ]; then + elif [[ -z "$arg_repo" ]]; then arg_repo=$i fi ;; @@ -155,13 +157,13 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # Here we want to find out the git remote name of user/repo, in order to # generate an appropriate revision list - if [ -z "$arg_repo" ]; then + if [[ -z "$arg_repo" ]]; then user=$(__hub_github_user) - if [ -z "$user" ]; then + if [[ -z "$user" ]]; then for i in $(__hub_github_repos); do remote=${i%%:*} repo=${i#*:} - if [ "$remote" = origin ]; then + if [[ "$remote" = origin ]]; then break fi done @@ -170,7 +172,7 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then remote=${i%%:*} repo=${i#*:} owner=${repo%%/*} - if [ "$user" = "$owner" ]; then + if [[ "$user" = "$owner" ]]; then break fi done @@ -193,13 +195,13 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then *..*) pfx="${cur_%%..*}..." cur_="${cur_##*..}" - __gitcomp_nl "$(__hub_revlist $remote)" "$pfx" "$cur_" + __gitcomp_nl "$(__hub_revlist "$remote")" "$pfx" "$cur_" ;; *) - if [ -z "${arg_repo}${rev}" ]; then - __gitcomp "$u $(__hub_github_repos '\o\n\p') $(__hub_revlist $remote)" - elif [ -z "$rev" ]; then - __gitcomp "$u $(__hub_revlist $remote)" + if [[ -z "${arg_repo}${rev}" ]]; then + __gitcomp "$u $(__hub_github_repos '\o\n\p') $(__hub_revlist "$remote")" + elif [[ -z "$rev" ]]; then + __gitcomp "$u $(__hub_revlist "$remote")" else __gitcomp "$u" fi @@ -210,7 +212,7 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # hub create [NAME] [-p] [-d DESCRIPTION] [-h HOMEPAGE] _git_create() { local i c=2 name repo flags="-p -d -h" - while [ $c -lt $cword ]; do + while [[ $c -lt $cword ]]; do i="${words[c]}" case "$i" in -d | -h) @@ -226,7 +228,7 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then esac ((c++)) done - if [ -z "$name" ]; then + if [[ -z "$name" ]]; then repo="$(basename "${PWD}")" fi case "$prev" in @@ -242,7 +244,7 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # hub fork [--no-remote] [--remote-name REMOTE] [--org ORGANIZATION] _git_fork() { local i c=2 flags="--no-remote --remote-name --org" - while [ $c -lt $cword ]; do + while [[ $c -lt $cword ]]; do i="${words[c]}" case "$i" in --org) @@ -274,7 +276,7 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # hub pull-request [-f] [-m |-F |-i |] [-b ] [-h ] [-a ] [-M ] [-l ] _git_pull_request() { local i c=2 flags="-f -m -F -i -b -h -a -M -l" - while [ $c -lt $cword ]; do + while [[ $c -lt $cword ]]; do i="${words[c]}" case "$i" in -m | -F | -i | -b | -h | -a | -M | -l) @@ -315,20 +317,20 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # Return $GITHUB_USER or the default github user defined in hub config # HOST - Host to be looked-up in hub config. Default is "github.com" __hub_github_user() { - if [ -n "$GITHUB_USER" ]; then - echo $GITHUB_USER + if [[ -n "$GITHUB_USER" ]]; then + echo "$GITHUB_USER" return fi local line h k v host=${1:-github.com} config=${HUB_CONFIG:-~/.config/hub} - if [ -f "$config" ]; then - while read line; do + if [[ -f "$config" ]]; then + while read -r line; do if [ "$line" = "---" ]; then continue fi k=${line%%:*} v=${line#*:} - if [ -z "$v" ]; then - if [ "$h" = "$host" ]; then + if [[ -z "$v" ]]; then + if [[ "$h" = "$host" ]]; then break fi h=$k @@ -336,7 +338,7 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then fi k=${k#* } v=${v#* } - if [ "$h" = "$host" ] && [ "$k" = "user" ]; then + if [[ "$h" = "$host" ]] && [[ "$k" = "user" ]]; then echo "$v" break fi @@ -353,11 +355,11 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # escaped characters (\n, \t ...etc) work # If omitted, prints all github repos in the format of "remote:owner/repo" __hub_github_repos() { - local f format=$1 - if [ -z "$(__gitdir)" ]; then + local format=$1 + if [[ -z "$(__gitdir)" ]]; then return fi - if [ -z "$format" ]; then + if [[ -z "$format" ]]; then format='\1:\2' else format=${format//\m/\1} @@ -372,16 +374,17 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # __hub_heads # List all local "branch", and remote "owner/repo:branch" __hub_heads() { - local i remote repo branch dir=$(__gitdir) - if [ -d "$dir" ]; then + local i remote repo branch dir + dir=$(__gitdir) + if [[ -d "$dir" ]]; then command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ "refs/heads/" for i in $(__hub_github_repos); do remote=${i%%:*} repo=${i#*:} command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ - "refs/remotes/${remote}/" | while read branch; do - echo "${repo}:${branch#${remote}/}" + "refs/remotes/${remote}/" | while read -r branch; do + echo "${repo}:${branch#"${remote}"/}" done done fi @@ -391,11 +394,12 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # List all tags, and branches under REMOTE, without the "remote/" prefix # REMOTE - Remote name to search branches from. Default is "origin" __hub_revlist() { - local i remote=${1:-origin} dir=$(__gitdir) - if [ -d "$dir" ]; then + local i remote=${1:-origin} dir + dir=$(__gitdir) + if [[ -d "$dir" ]]; then command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ - "refs/remotes/${remote}/" | while read i; do - echo "${i#${remote}/}" + "refs/remotes/${remote}/" | while read -r i; do + echo "${i#"${remote}"/}" done command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ "refs/tags/" diff --git a/completion/available/invoke.completion.bash b/completion/available/invoke.completion.bash index 89449445cd..da78213775 100644 --- a/completion/available/invoke.completion.bash +++ b/completion/available/invoke.completion.bash @@ -1,3 +1,4 @@ +# shellcheck shell=bash # Invoke (pyinvoke.org) tab-completion script to be sourced with Bash shell. # Copyright (c) 2020 Jeff Forcier. @@ -26,13 +27,13 @@ # https://github.com/pyinvoke/invoke/blob/master/completion/bash _complete_invoke() { - local candidates + local candidates line # COMP_WORDS contains the entire command string up til now (including # program name). # We hand it to Invoke so it can figure out the current context: spit back # core options, task names, the current task's options, or some combo. - candidates=$(invoke --complete -- ${COMP_WORDS[*]}) + candidates=$(invoke --complete -- "${COMP_WORDS[@]}") # `compgen -W` takes list of valid options & a partial word & spits back # possible matches. Necessary for any partial word completions (vs @@ -43,7 +44,7 @@ _complete_invoke() { # our candidate list which actually matches. # # COMPREPLY is the list of valid completions handed back to `complete`. - COMPREPLY=($(compgen -W "${candidates}" -- $2)) + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${candidates}" -- "$2") } # Tell shell builtin to use the above for completing 'inv'/'invoke': diff --git a/completion/available/kind.completion.bash b/completion/available/kind.completion.bash index b48f0ef29a..dcae12b5ad 100644 --- a/completion/available/kind.completion.bash +++ b/completion/available/kind.completion.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash if _command_exists kind; then eval "$(kind completion bash)" diff --git a/completion/available/maven.completion.bash b/completion/available/maven.completion.bash index 0af42a882a..54c28c4d2a 100644 --- a/completion/available/maven.completion.bash +++ b/completion/available/maven.completion.bash @@ -1,4 +1,5 @@ -#!/usr/bin/env bash +# shellcheck shell=bash +# shellcheck disable=SC2034,SC2207 # Bash Maven completion _mvn() { @@ -24,9 +25,9 @@ _mvn() { # Work-around borrowed from the darcs work-around for the same # issue. colonprefixes=${cur%"${cur##*:}"} - COMPREPLY=($(compgen -W '$cmds' -- $cur)) + COMPREPLY=($(compgen -W "$cmds" -- "$cur")) local i=${#COMPREPLY[*]} - while [ $((--i)) -ge 0 ]; do + while [ "$((--i))" -ge 0 ]; do COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"} done diff --git a/completion/available/ng.completion.bash b/completion/available/ng.completion.bash index 5fedb44459..af2e8374f3 100644 --- a/completion/available/ng.completion.bash +++ b/completion/available/ng.completion.bash @@ -1,3 +1,4 @@ +# shellcheck shell=bash if _command_exists ng; then # No longer supported, please see https://github.com/angular/angular-cli/issues/11043 # Fix courtesy of https://stackoverflow.com/questions/50194674/ng-completion-no-longer-exists diff --git a/completion/available/nvm.completion.bash b/completion/available/nvm.completion.bash index 4b4147ec44..28a8eea516 100644 --- a/completion/available/nvm.completion.bash +++ b/completion/available/nvm.completion.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # nvm (Node Version Manager) completion diff --git a/completion/available/projects.completion.bash b/completion/available/projects.completion.bash index 196d2bb8a7..8790e41040 100644 --- a/completion/available/projects.completion.bash +++ b/completion/available/projects.completion.bash @@ -1,3 +1,4 @@ +# shellcheck shell=bash # Ensure that we log to doctor so the user can address these issues _is_function _init_completion \ || _log_error '_init_completion not found. Ensure bash-completion 2.0 or newer is installed and configured properly.' @@ -11,7 +12,8 @@ _pj() { shift [ "$1" == "open" ] && shift - local cur prev words cword + # shellcheck disable=SC2034 + local cur prev words cword # these are set by the call to _init_completion _init_completion || return local IFS=$'\n' i j k @@ -24,11 +26,11 @@ _pj() { for i in ${BASH_IT_PROJECT_PATHS//:/$'\n'}; do # create an array of matched subdirs k="${#COMPREPLY[@]}" - for j in $(compgen -d $i/$cur); do - if [[ ($mark_symdirs && -L $j || $mark_dirs && ! -L $j) && ! -d ${j#$i/} ]]; then + for j in $(compgen -d "$i/$cur"); do + if [[ ($mark_symdirs && -L $j || $mark_dirs && ! -L $j) && ! -d ${j#"$i"/} ]]; then j+="/" fi - COMPREPLY[k++]=${j#$i/} + COMPREPLY[k++]=${j#"$i"/} done done diff --git a/completion/available/rake.completion.bash b/completion/available/rake.completion.bash index 31b7f23b8f..8160af1957 100644 --- a/completion/available/rake.completion.bash +++ b/completion/available/rake.completion.bash @@ -1,15 +1,17 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # Bash completion support for Rake, Ruby Make. export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/} _rakecomplete() { if [ -f Rakefile ]; then - recent=$(ls -t .rake_tasks~ Rakefile **/*.rake 2> /dev/null | head -n 1) + #shellcheck disable=SC2012 + recent=$(ls -t -- .rake_tasks~ Rakefile **/*.rake 2> /dev/null | head -n 1) if [[ $recent != '.rake_tasks~' ]]; then rake --silent --tasks | cut -d " " -f 2 > .rake_tasks~ fi - COMPREPLY=($(compgen -W "$(cat .rake_tasks~)" -- ${COMP_WORDS[COMP_CWORD]})) + local line + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "$(cat .rake_tasks~)" -- "${COMP_WORDS[COMP_CWORD]}") return 0 fi } diff --git a/completion/available/ssh.completion.bash b/completion/available/ssh.completion.bash index e95ad76c25..3252267fb0 100644 --- a/completion/available/ssh.completion.bash +++ b/completion/available/ssh.completion.bash @@ -1,10 +1,10 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # Bash completion support for ssh. export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/} _sshcomplete() { - local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}" + local line CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}" if [[ ${CURRENT_PROMPT} == *@* ]]; then local OPTIONS="-P ${CURRENT_PROMPT/@*/}@ -- ${CURRENT_PROMPT/*@/}" else @@ -17,20 +17,21 @@ _sshcomplete() { | awk '{for (i=2; i<=NF; i++) print $i}' \ | sed -Ee "s|^([^/~])|$HOME/.ssh/\1|" -e "s|^~/|$HOME/|"); do if [ -r "$fl" ]; then - COMPREPLY=(${COMPREPLY[@]} $(compgen -W "$(grep -i ^Host "$fl" | grep -v '[*!]' | awk '{for (i=2; i<=NF; i++) print $i}')" ${OPTIONS})) + #shellcheck disable=SC2086 + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "$(grep -i ^Host "$fl" | grep -v '[*!]' | awk '{for (i=2; i<=NF; i++) print $i}')" ${OPTIONS}) fi done # parse all hosts found in .ssh/known_hosts - if [ -r "$HOME/.ssh/known_hosts" ]; then - if grep -v -q -e '^ ssh-rsa' "$HOME/.ssh/known_hosts"; then - COMPREPLY=(${COMPREPLY[@]} $(compgen -W "$(awk '{print $1}' "$HOME/.ssh/known_hosts" | grep -v ^\| | cut -d, -f 1 | sed -e 's/\[//g' | sed -e 's/\]//g' | cut -d: -f1 | grep -v ssh-rsa)" ${OPTIONS})) - fi + if [ -r "$HOME/.ssh/known_hosts" ] && grep -v -q -e '^ ssh-rsa' "$HOME/.ssh/known_hosts"; then + #shellcheck disable=SC2086 + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "$(awk '{print $1}' "$HOME/.ssh/known_hosts" | grep -v ^\| | cut -d, -f 1 | sed -e 's/\[//g' | sed -e 's/\]//g' | cut -d: -f1 | grep -v ssh-rsa)" ${OPTIONS}) fi # parse hosts defined in /etc/hosts if [ -r /etc/hosts ]; then - COMPREPLY=(${COMPREPLY[@]} $(compgen -W "$(grep -v '^[[:space:]]*$' /etc/hosts | grep -v '^#' | awk '{for (i=2; i<=NF; i++) print $i}')" ${OPTIONS})) + #shellcheck disable=SC2086 + while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "$(grep -v '^[[:space:]]*$' /etc/hosts | grep -v '^#' | awk '{for (i=2; i<=NF; i++) print $i}')" ${OPTIONS}) fi return 0 diff --git a/completion/available/terraform.completion.bash b/completion/available/terraform.completion.bash index fcba7d7ba8..3383a4f7e8 100644 --- a/completion/available/terraform.completion.bash +++ b/completion/available/terraform.completion.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # Make sure terraform is installed _command_exists terraform || return diff --git a/completion/available/test_kitchen.completion.bash b/completion/available/test_kitchen.completion.bash index 6a347c41e9..c53c303a5f 100644 --- a/completion/available/test_kitchen.completion.bash +++ b/completion/available/test_kitchen.completion.bash @@ -1,3 +1,5 @@ +# shellcheck shell=bash +# shellcheck disable=SC2120,SC2207 __kitchen_instance_list() { # cache to .kitchen.list.yml if [[ .kitchen.yml -nt .kitchen.list.yml || .kitchen.local.yml -nt .kitchen.list.yml ]]; then @@ -14,15 +16,15 @@ __kitchen_options() { case $prev in converge | create | destroy | diagnose | list | login | setup | test | verify) - COMPREPLY=($(compgen -W "$(__kitchen_instance_list)" -- ${cur})) + COMPREPLY=($(compgen -W "$(__kitchen_instance_list)" -- "${cur}")) return 0 ;; driver) - COMPREPLY=($(compgen -W "create discover help" -- ${cur})) + COMPREPLY=($(compgen -W "create discover help" -- "${cur}")) return 0 ;; *) - COMPREPLY=($(compgen -W "console converge create destroy driver help init list login setup test verify version" -- ${cur})) + COMPREPLY=($(compgen -W "console converge create destroy driver help init list login setup test verify version" -- "${cur}")) return 0 ;; esac diff --git a/completion/available/tmux.completion.bash b/completion/available/tmux.completion.bash index 08a003dea3..674afaf70f 100644 --- a/completion/available/tmux.completion.bash +++ b/completion/available/tmux.completion.bash @@ -1,17 +1,19 @@ -#!/usr/bin/env bash +# shellcheck shell=bash +# shellcheck disable=SC2120,SC2207 +# A future refactor can fix this better. # tmux completion # See: http://www.debian-administration.org/articles/317 for how to write more. # Usage: Put "source bash_completion_tmux.sh" into your .bashrc _tmux_expand() { - [ "$cur" != "${cur%\\}" ] && cur="$cur"'\' + [[ "$cur" != "${cur%\\}" ]] && cur="$cur\\" if [[ "$cur" == \~*/* ]]; then - eval cur=$cur + eval "cur=$cur" else if [[ "$cur" == \~* ]]; then cur=${cur#\~} - COMPREPLY=($(compgen -P '~' -u $cur)) + COMPREPLY=($(compgen -P '~' -u "$cur")) return ${#COMPREPLY[@]} fi fi @@ -21,53 +23,52 @@ _tmux_filedir() { local IFS=' ' _tmux_expand || return 0 - if [ "$1" = -d ]; then - COMPREPLY=(${COMPREPLY[@]} $(compgen -d -- $cur)) + if [[ "$1" = -d ]]; then + COMPREPLY=("${COMPREPLY[@]}" $(compgen -d -- "$cur")) return 0 fi - COMPREPLY=(${COMPREPLY[@]} $(eval compgen -f -- \"$cur\")) + COMPREPLY=("${COMPREPLY[@]}" $(eval "compgen -f -- \"$cur\"")) } function _tmux_complete_client() { local IFS=$'\n' local cur="${1}" - COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-clients 2> /dev/null | cut -f 1 -d ':')" -- "${cur}")) + COMPREPLY+=($(compgen -W "$(tmux -q list-clients 2> /dev/null | cut -f 1 -d ':')" -- "${cur}")) } function _tmux_complete_session() { local IFS=$'\n' local cur="${1}" - COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-sessions 2> /dev/null | cut -f 1 -d ':')" -- "${cur}")) + COMPREPLY+=($(compgen -W "$(tmux -q list-sessions 2> /dev/null | cut -f 1 -d ':')" -- "${cur}")) } function _tmux_complete_window() { local IFS=$'\n' local cur="${1}" - local session_name="$(echo "${cur}" | sed 's/\\//g' | cut -d ':' -f 1)" - local sessions + local session_name sessions + session_name="$(echo "${cur}" | sed 's/\\//g' | cut -d ':' -f 1)" sessions="$(tmux -q list-sessions 2> /dev/null | sed -re 's/([^:]+:).*$/\1/')" if [[ -n "${session_name}" ]]; then sessions="${sessions} $(tmux -q list-windows -t "${session_name}" 2> /dev/null | sed -re 's/^([^:]+):.*$/'"${session_name}"':\1/')" fi - cur="$(echo "${cur}" | sed -e 's/:/\\\\:/')" - sessions="$(echo "${sessions}" | sed -e 's/:/\\\\:/')" - COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W "${sessions}" -- "${cur}")) + cur=${cur/:/\\\\:} + sessions=${sessions/:/\\\\:} + COMPREPLY+=($(compgen -W "${sessions}" -- "${cur}")) } _tmux() { local cur prev local i cmd cmd_index option option_index - local opts="" COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD - 1]}" - if [ ${prev} == -f ]; then + if [[ "${prev}" == -f ]]; then _tmux_filedir else # Search for the command local skip_next=0 - for ((i = 1; $i <= $COMP_CWORD; i++)); do + for ((i = 1; i <= COMP_CWORD; i++)); do if [[ ${skip_next} -eq 1 ]]; then #echo "Skipping" skip_next=0 @@ -82,7 +83,7 @@ _tmux() { # Search for the last option command skip_next=0 - for ((i = 1; $i <= $COMP_CWORD; i++)); do + for ((i = 1; i <= COMP_CWORD; i++)); do if [[ ${skip_next} -eq 1 ]]; then #echo "Skipping" skip_next=0 @@ -99,7 +100,7 @@ _tmux() { if [[ $COMP_CWORD -le $cmd_index ]]; then # The user has not specified a command yet - COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W "$(tmux start-server \; list-commands | cut -d' ' -f1)" -- "${cur}")) + COMPREPLY=("${COMPREPLY[@]:-}" $(compgen -W "$(tmux start-server \; list-commands | cut -d' ' -f1)" -- "${cur}")) else case ${cmd} in attach-session | attach) @@ -132,7 +133,7 @@ _tmux() { -[n | d | s]) options="-d -n -s -t --" ;; *) if [[ ${COMP_WORDS[option_index]} == -- ]]; then - _command_offset ${option_index} + _command_offset "${option_index}" else options="-d -n -s -t --" fi @@ -183,7 +184,7 @@ _tmux() { fi # not -f if [[ -n "${options}" ]]; then - COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W "${options}" -- "${cur}")) + COMPREPLY=("${COMPREPLY[@]:-}" $(compgen -W "${options}" -- "${cur}")) fi return 0 diff --git a/completion/available/virtualbox.completion.bash b/completion/available/virtualbox.completion.bash index edb2e714c2..9c1a5444f9 100644 --- a/completion/available/virtualbox.completion.bash +++ b/completion/available/virtualbox.completion.bash @@ -1,6 +1,8 @@ -#!/usr/bin/bash +# shellcheck shell=bash +# shellcheck disable=SC2120,SC2207 + _vboxmanage_realopts() { - echo $(vboxmanage | grep -i vboxmanage | cut -d' ' -f2 | grep '\[' | tr -s '[\[\|\]\n' ' ') + vboxmanage | grep -i vboxmanage | cut -d' ' -f2 | grep '\[' | tr -s '\[\|\]\n' ' ' echo " " } @@ -16,13 +18,13 @@ __vboxmanage_startvm() { MATCH=1 fi done - (($MATCH == 0)) && AVAILABLE="$AVAILABLE $VM " + ((MATCH == 0)) && AVAILABLE="$AVAILABLE $VM " done - echo $AVAILABLE + echo "$AVAILABLE" } __vboxmanage_list() { - INPUT=$(vboxmanage list | tr -s '[\[\]\|\n]' ' ' | cut -d' ' -f4-) + INPUT=$(vboxmanage list | tr -s '\[\]\|\n' ' ' | cut -d' ' -f4-) PRUNED="" if [ "$1" == "long" ]; then @@ -36,12 +38,12 @@ __vboxmanage_list() { PRUNED=$INPUT fi - echo $PRUNED + echo "$PRUNED" } __vboxmanage_list_vms() { VMS="" - if [ "x$1" == "x" ]; then + if [ "$1" == "" ]; then SEPARATOR=" " else SEPARATOR=$1 @@ -52,7 +54,7 @@ __vboxmanage_list_vms() { VMS="${VMS}${VM}" done - echo $VMS + echo "$VMS" } __vboxmanage_list_runningvms() { @@ -68,7 +70,7 @@ __vboxmanage_list_runningvms() { VMS="${VMS}${VM}" done - echo $VMS + echo "$VMS" } @@ -102,7 +104,7 @@ __vboxmanage_default() { # echo "DEBUG: default: |$p1|$p2|$p3|$p4|" case ${cur} in -*) - echo $opts + echo "$opts" # COMPREPLY=($(compgen -W "${opts}" -- ${cur})) return 0 ;; @@ -111,7 +113,7 @@ __vboxmanage_default() { for WORD in $opts; do MATCH=0 for OPT in "${COMP_WORDS[@]}"; do - # opts=$(echo ${opts} | grep -v $OPT); + # opts=$(echo "${opts}" | grep -v $OPT); if [ "$OPT" == "$WORD" ]; then MATCH=1 break @@ -133,19 +135,19 @@ __vboxmanage_default() { break fi done - (($MATCH == 1)) && continue + ((MATCH == 1)) && continue pruned="$pruned $WORD" done - # COMPREPLY=($(compgen -W "${pruned}" -- ${cur})) - echo $pruned + # COMPREPLY=($(compgen -W "${pruned}" -- "${cur}")) + echo "$pruned" return 0 } _vboxmanage() { # vboxmanage | grep -i vboxmanage | cut -d' ' -f2 | sort | uniq - local cur p1 p2 p3 p4 opts + local cur opts COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD - 1]}" @@ -156,7 +158,7 @@ _vboxmanage() { # In case current is complete command case $cur in startvm | list | controlvm) - COMPREPLY=($(compgen -W "$cur ")) + COMPREPLY=($(compgen -W "${cur}")) return 0 ;; esac @@ -168,16 +170,16 @@ _vboxmanage() { -l | --long) opts=$(__vboxmanage_list "long") - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) return 0 ;; startvm | list) - opts=$(__vboxmanage_$prev) - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + opts=$(__vboxmanage_"$prev") + COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) return 0 ;; --type) - COMPREPLY=($(compgen -W "gui headless" -- ${cur})) + COMPREPLY=($(compgen -W "gui headless" -- "${cur}")) return 0 ;; gui | headless) @@ -187,12 +189,12 @@ _vboxmanage() { vboxmanage | -q | --nologo) # echo "Got vboxmanage" opts=$(__vboxmanage_default) - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) return 0 ;; controlvm) opts=$(__vboxmanage_list_vms) - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) return 0 ;; esac @@ -204,12 +206,12 @@ _vboxmanage() { case $pprev in startvm) opts="--type" - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) return 0 ;; controlvm) opts=$(__vboxmanage_controlvm) - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) return 0 ;; esac diff --git a/hooks/check-clean-files-txt.sh b/hooks/check-clean-files-txt.sh index a37ee777d5..0bc8d294f3 100755 --- a/hooks/check-clean-files-txt.sh +++ b/hooks/check-clean-files-txt.sh @@ -9,6 +9,7 @@ fi function compare_lines() { prev="" + local line while read -r line; do # Skip unimportant lines [[ $line =~ "#" ]] && continue