From 4424b89e4079e824d68f70778d4c23386e725164 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Wed, 29 Jan 2025 13:50:49 +0200 Subject: [PATCH 01/22] bring to compliance: virtualbox.completion --- clean_files.txt | 57 +------------------ .../available/virtualbox.completion.bash | 50 ++++++++-------- 2 files changed, 27 insertions(+), 80 deletions(-) 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/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 From fc623c5861b54f58a9abdaaec81ddb28d74925aa Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Wed, 29 Jan 2025 14:04:42 +0200 Subject: [PATCH 02/22] bring to compliance: tmux.completion Co-authored-by: Koichi Murase --- completion/available/tmux.completion.bash | 36 ++++++++++++----------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/completion/available/tmux.completion.bash b/completion/available/tmux.completion.bash index 08a003dea3..de02e11003 100644 --- a/completion/available/tmux.completion.bash +++ b/completion/available/tmux.completion.bash @@ -1,17 +1,20 @@ -#!/usr/bin/env bash +# shellcheck shell=bash +# shellcheck disable=SC2120,SC2207,SC2206 +# note: adding the SC2206 exception here is ugly. +# 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 @@ -22,10 +25,10 @@ _tmux_filedir() { ' _tmux_expand || return 0 if [ "$1" = -d ]; then - COMPREPLY=(${COMPREPLY[@]} $(compgen -d -- $cur)) + COMPREPLY=("${COMPREPLY[@]}" $(compgen -d -- "$cur")) return 0 fi - COMPREPLY=(${COMPREPLY[@]} $(eval compgen -f -- \"$cur\")) + COMPREPLY=("${COMPREPLY[@]}" $(eval "compgen -f -- \"$cur\"")) } function _tmux_complete_client() { @@ -41,33 +44,32 @@ function _tmux_complete_session() { 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/:/\\\\:/')" + cur=${cur/:/\\\\:} + sessions=${sessions/:/\\\\:} COMPREPLY=(${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 +84,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 +101,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 +134,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 +185,7 @@ _tmux() { fi # not -f if [[ -n "${options}" ]]; then - COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W "${options}" -- "${cur}")) + COMPREPLY=("${COMPREPLY[@]:-}" $(compgen -W "${options}" -- "${cur}")) fi return 0 From e0ceb94aec2fda36d174644d83710549c322714c Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Wed, 29 Jan 2025 14:07:46 +0200 Subject: [PATCH 03/22] bring to compliance: maven.completion --- completion/available/maven.completion.bash | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/completion/available/maven.completion.bash b/completion/available/maven.completion.bash index 0af42a882a..23b674d55c 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,7 +25,7 @@ _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 COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"} From aaf21e4088184dfd94649aa31cf7290ff4ff17fc Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Wed, 29 Jan 2025 14:15:22 +0200 Subject: [PATCH 04/22] bring to compliance: terraform.completion --- completion/available/terraform.completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 840c8fd3553143cb05332e7a36968038b4ef9cbd Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Wed, 29 Jan 2025 14:17:05 +0200 Subject: [PATCH 05/22] bring to compliance: test_kitchen.completion --- completion/available/test_kitchen.completion.bash | 8 +++++--- hooks/check-clean-files-txt.sh | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) 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/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 From b7e75576e0ae34d3f2938b0fac3da7ab9ac64786 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Wed, 29 Jan 2025 14:19:59 +0200 Subject: [PATCH 06/22] bring to compliance: git_flow.completion --- completion/available/git_flow.completion.bash | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) 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 From 9c2edda804f72b4cd087d8a6f55b26709824caeb Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Wed, 29 Jan 2025 14:37:30 +0200 Subject: [PATCH 07/22] bring to compliance: git_flow_avh.completion --- .../available/git_flow_avh.completion.bash | 65 +++++++++++-------- 1 file changed, 38 insertions(+), 27 deletions(-) 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 } From 761054de6409779c905e925115c432b94965ff92 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sun, 26 Jan 2025 15:52:23 +0200 Subject: [PATCH 08/22] clean up AWS plugin --- plugins/available/aws.plugin.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/available/aws.plugin.bash b/plugins/available/aws.plugin.bash index f9e51f3571..7030ffe50d 100644 --- a/plugins/available/aws.plugin.bash +++ b/plugins/available/aws.plugin.bash @@ -109,12 +109,12 @@ function __awskeys_comp { show | export) local profile_list profile_list="$(__awskeys_list | grep " ")" - mapfile -t COMPREPLY < <(compgen -W "${profile_list}" -- "${cur}") + IFS=" " read -r -a COMPREPLY <<< "$(compgen -W "${profile_list}" -- "${cur}")" return 0 ;; esac - mapfile -t COMPREPLY < <(compgen -W "${opts}" -- "${cur}") + IFS=" " read -r -a COMPREPLY <<< "$(compgen -W "${opts}" -- "${cur}")" return 0 } From fbd04292b451367b79823e52592dee3861b6bf20 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Mon, 27 Jan 2025 09:30:10 +0200 Subject: [PATCH 09/22] Cleanup all remaining plugins --- plugins/available/aws.plugin.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/available/aws.plugin.bash b/plugins/available/aws.plugin.bash index 7030ffe50d..f9e51f3571 100644 --- a/plugins/available/aws.plugin.bash +++ b/plugins/available/aws.plugin.bash @@ -109,12 +109,12 @@ function __awskeys_comp { show | export) local profile_list profile_list="$(__awskeys_list | grep " ")" - IFS=" " read -r -a COMPREPLY <<< "$(compgen -W "${profile_list}" -- "${cur}")" + mapfile -t COMPREPLY < <(compgen -W "${profile_list}" -- "${cur}") return 0 ;; esac - IFS=" " read -r -a COMPREPLY <<< "$(compgen -W "${opts}" -- "${cur}")" + mapfile -t COMPREPLY < <(compgen -W "${opts}" -- "${cur}") return 0 } From d3a68c8bdfba492f975d0bcb33bc8eb08dd9776c Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Mon, 27 Jan 2025 13:44:53 +0200 Subject: [PATCH 10/22] last details From 0386181bda0f5f3387a49ca60fcdb6d92cdbb240 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sat, 1 Feb 2025 11:11:07 +0200 Subject: [PATCH 11/22] bring to compliance: rake.completion --- completion/available/rake.completion.bash | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 } From 16fcc2ad1fc4cf09bcb5153b6e400cf35ac3f837 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sat, 1 Feb 2025 11:16:31 +0200 Subject: [PATCH 12/22] bring to compliance: projects.completion --- completion/available/projects.completion.bash | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 From ba6afac0a9a35d65048295f7610db5cd6a71d2fd Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sat, 1 Feb 2025 11:16:50 +0200 Subject: [PATCH 13/22] bring to compliance: nvm.completion --- completion/available/nvm.completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 2f703545be34e8777e8d4636fe7443a10ea9a4a9 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sat, 1 Feb 2025 11:17:05 +0200 Subject: [PATCH 14/22] bring to compliance: ng.completion --- completion/available/ng.completion.bash | 1 + 1 file changed, 1 insertion(+) 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 From 937d1af0815e3c06b4727d6dbe0bea920f6d8a73 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sat, 1 Feb 2025 11:17:20 +0200 Subject: [PATCH 15/22] bring to compliance: kind.completion --- completion/available/kind.completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)" From 816014550ce9043771075bca2a7a4168c5085aec Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sat, 1 Feb 2025 11:19:43 +0200 Subject: [PATCH 16/22] bring to compliance: gulp.completion --- completion/available/gulp.completion.bash | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 From 4e263f6695e2623ab10d8f5adb80d3aadb6e344b Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sat, 1 Feb 2025 11:23:02 +0200 Subject: [PATCH 17/22] bring to compliance: grunt.completion --- completion/available/grunt.completion.bash | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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 From db985f03152321804e6b249616c2266a433751fb Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sat, 1 Feb 2025 11:30:57 +0200 Subject: [PATCH 18/22] bring to compliance: hub.completion Update completion/available/hub.completion.bash Co-authored-by: Koichi Murase make the comparisons more elegant and save an invokation of an external bin --- completion/available/hub.completion.bash | 54 +++++++++++++----------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/completion/available/hub.completion.bash b/completion/available/hub.completion.bash index b607fdd1d7..c411dcfb63 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#*/}" @@ -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)" + __gitcomp "$u $(__hub_github_repos '\o\n\p') $(__hub_revlist "$remote")" elif [ -z "$rev" ]; then - __gitcomp "$u $(__hub_revlist $remote)" + __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) @@ -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) @@ -316,12 +318,12 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # HOST - Host to be looked-up in hub config. Default is "github.com" __hub_github_user() { if [ -n "$GITHUB_USER" ]; then - echo $GITHUB_USER + 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 + while read -r line; do if [ "$line" = "---" ]; then continue fi @@ -353,7 +355,7 @@ 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 + local format=$1 if [ -z "$(__gitdir)" ]; then return fi @@ -372,7 +374,8 @@ 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) + 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/" @@ -380,8 +383,8 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then 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) + 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/" From 3722758c81cbcc4c3012cdf0f101814508d534a6 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sat, 1 Feb 2025 11:32:41 +0200 Subject: [PATCH 19/22] bring to compliance: invoke.completion --- completion/available/invoke.completion.bash | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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': From 6a2d699ad98210e743ebca631b30125181b17b59 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sat, 1 Feb 2025 11:39:34 +0200 Subject: [PATCH 20/22] bring to compliance: ssh.completion --- completion/available/ssh.completion.bash | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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 From 9c78f5cd2ffdf49f5a3e83c57fa3adbf9fb329c1 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sat, 1 Feb 2025 15:31:34 +0200 Subject: [PATCH 21/22] Update completion/available/maven.completion.bash Co-authored-by: Koichi Murase --- completion/available/maven.completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completion/available/maven.completion.bash b/completion/available/maven.completion.bash index 23b674d55c..54c28c4d2a 100644 --- a/completion/available/maven.completion.bash +++ b/completion/available/maven.completion.bash @@ -27,7 +27,7 @@ _mvn() { colonprefixes=${cur%"${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 From f4f3b147f26e99abe0e24252f5ea1b09ec1278df Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sat, 1 Feb 2025 16:10:23 +0200 Subject: [PATCH 22/22] Last few fixes after consulting Koichi-san. --- completion/available/hub.completion.bash | 38 +++++++++++------------ completion/available/tmux.completion.bash | 15 +++++---- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/completion/available/hub.completion.bash b/completion/available/hub.completion.bash index c411dcfb63..f730274320 100644 --- a/completion/available/hub.completion.bash +++ b/completion/available/hub.completion.bash @@ -128,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 @@ -147,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 ;; @@ -157,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 @@ -172,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 @@ -198,9 +198,9 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then __gitcomp_nl "$(__hub_revlist "$remote")" "$pfx" "$cur_" ;; *) - if [ -z "${arg_repo}${rev}" ]; then + if [[ -z "${arg_repo}${rev}" ]]; then __gitcomp "$u $(__hub_github_repos '\o\n\p') $(__hub_revlist "$remote")" - elif [ -z "$rev" ]; then + elif [[ -z "$rev" ]]; then __gitcomp "$u $(__hub_revlist "$remote")" else __gitcomp "$u" @@ -228,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 @@ -317,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 + 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 + 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 @@ -338,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 @@ -356,10 +356,10 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # If omitted, prints all github repos in the format of "remote:owner/repo" __hub_github_repos() { local format=$1 - if [ -z "$(__gitdir)" ]; then + if [[ -z "$(__gitdir)" ]]; then return fi - if [ -z "$format" ]; then + if [[ -z "$format" ]]; then format='\1:\2' else format=${format//\m/\1} @@ -376,7 +376,7 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then __hub_heads() { local i remote repo branch dir dir=$(__gitdir) - if [ -d "$dir" ]; then + if [[ -d "$dir" ]]; then command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ "refs/heads/" for i in $(__hub_github_repos); do @@ -396,7 +396,7 @@ if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then __hub_revlist() { local i remote=${1:-origin} dir dir=$(__gitdir) - if [ -d "$dir" ]; then + if [[ -d "$dir" ]]; then command git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ "refs/remotes/${remote}/" | while read -r i; do echo "${i#"${remote}"/}" diff --git a/completion/available/tmux.completion.bash b/completion/available/tmux.completion.bash index de02e11003..674afaf70f 100644 --- a/completion/available/tmux.completion.bash +++ b/completion/available/tmux.completion.bash @@ -1,6 +1,5 @@ # shellcheck shell=bash -# shellcheck disable=SC2120,SC2207,SC2206 -# note: adding the SC2206 exception here is ugly. +# shellcheck disable=SC2120,SC2207 # A future refactor can fix this better. # tmux completion @@ -8,7 +7,7 @@ # 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" else @@ -24,7 +23,7 @@ _tmux_filedir() { local IFS=' ' _tmux_expand || return 0 - if [ "$1" = -d ]; then + if [[ "$1" = -d ]]; then COMPREPLY=("${COMPREPLY[@]}" $(compgen -d -- "$cur")) return 0 fi @@ -34,12 +33,12 @@ _tmux_filedir() { 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' @@ -54,7 +53,7 @@ function _tmux_complete_window() { fi cur=${cur/:/\\\\:} sessions=${sessions/:/\\\\:} - COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W "${sessions}" -- "${cur}")) + COMPREPLY+=($(compgen -W "${sessions}" -- "${cur}")) } _tmux() { @@ -64,7 +63,7 @@ _tmux() { 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