From 2d473966b541fbcee59c7235552befbc33f3ee41 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 19 Nov 2024 23:56:15 +0200 Subject: [PATCH 1/8] fixing plugins/available/z_autoenv.plugin.bash --- clean_files.txt | 7 +-- plugins/available/z_autoenv.plugin.bash | 68 ++++++++++++------------- 2 files changed, 34 insertions(+), 41 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 88fbd3e648..3ea548ad59 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -134,14 +134,9 @@ plugins/available/textmate.plugin.bash plugins/available/todo.plugin.bash plugins/available/url.plugin.bash plugins/available/xterm.plugin.bash +plugins/available/z_autoenv.plugin.bash plugins/available/zoxide.plugin.bash -# tests -# -test/completion/aliases.completion.bats -test/run -test/test_helper.bash - # themes # themes/90210 diff --git a/plugins/available/z_autoenv.plugin.bash b/plugins/available/z_autoenv.plugin.bash index a2f97d2833..7d3f1736f4 100644 --- a/plugins/available/z_autoenv.plugin.bash +++ b/plugins/available/z_autoenv.plugin.bash @@ -1,45 +1,43 @@ +# shellcheck shell=bash +# shellcheck disable=SC2207 cite about-plugin about-plugin 'source into environment when cding to directories' -if [[ -n "${ZSH_VERSION}" ]] -then __array_offset=0 -else __array_offset=1 +if [[ -n "${ZSH_VERSION}" ]]; then + __array_offset=0 +else + __array_offset=1 fi -autoenv_init() -{ - typeset target home _file - typeset -a _files - target=$1 - home="${HOME%/*}" +function autoenv_init { + typeset home _file + typeset -a _files + home="${HOME%/*}" - _files=( $( - while [[ "$PWD" != "/" && "$PWD" != "$home" ]] - do - _file="$PWD/.env" - if [[ -e "${_file}" ]] - then echo "${_file}" - fi - builtin cd .. - done - ) ) + _files=($( + while [[ "$PWD" != "/" && "$PWD" != "$home" ]]; do + _file="$PWD/.env" + if [[ -e "${_file}" ]]; then + echo "${_file}" + fi + builtin cd .. || return + done + )) - _file=${#_files[@]} - while (( _file > 0 )) - do - source "${_files[_file-__array_offset]}" - : $(( _file -= 1 )) - done + _file=${#_files[@]} + while ((_file > 0)); do + # shellcheck disable=SC1090 + source "${_files[_file - __array_offset]}" + : $((_file -= 1)) + done } -cd() -{ - if builtin cd "$@" - then - autoenv_init - return 0 - else - echo "else?" - return $? - fi +cd() { + if builtin cd "$@"; then + autoenv_init + return 0 + else + echo "else?" + return $? + fi } From aa31ee504e7f596cf889b63ec6660b96a2f175e6 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 19 Nov 2024 23:57:23 +0200 Subject: [PATCH 2/8] fixing plugins/available/virtualenv.plugin.bash --- clean_files.txt | 1 + plugins/available/virtualenv.plugin.bash | 32 +++++++++++------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 3ea548ad59..f42ffea7a9 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -133,6 +133,7 @@ plugins/available/ruby.plugin.bash plugins/available/textmate.plugin.bash plugins/available/todo.plugin.bash plugins/available/url.plugin.bash +plugins/available/virtualenv.plugin.bash plugins/available/xterm.plugin.bash plugins/available/z_autoenv.plugin.bash plugins/available/zoxide.plugin.bash diff --git a/plugins/available/virtualenv.plugin.bash b/plugins/available/virtualenv.plugin.bash index 41d55ddfb1..94ea39f4d2 100644 --- a/plugins/available/virtualenv.plugin.bash +++ b/plugins/available/virtualenv.plugin.bash @@ -11,35 +11,33 @@ elif _command_exists virtualenvwrapper.sh; then source virtualenvwrapper.sh fi - function mkvenv { - about 'create a new virtualenv for this directory' - group 'virtualenv' + about 'create a new virtualenv for this directory' + group 'virtualenv' - local cwd="${PWD##*/}" - mkvirtualenv --distribute "$cwd" + local cwd="${PWD##*/}" + mkvirtualenv --distribute "$cwd" } - function mkvbranch { - about 'create a new virtualenv for the current branch' - group 'virtualenv' + about 'create a new virtualenv for the current branch' + group 'virtualenv' - local cwd="${PWD##*/}" - mkvirtualenv --distribute "${cwd}@${SCM_BRANCH}" + local cwd="${PWD##*/}" + mkvirtualenv --distribute "${cwd}@${SCM_BRANCH}" } function wovbranch { - about 'sets workon branch' - group 'virtualenv' + about 'sets workon branch' + group 'virtualenv' - local cwd="${PWD##*/}" - workon "${cwd}@${SCM_BRANCH}" + local cwd="${PWD##*/}" + workon "${cwd}@${SCM_BRANCH}" } function wovenv { - about 'works on the virtualenv for this directory' - group 'virtualenv' + about 'works on the virtualenv for this directory' + group 'virtualenv' - workon "${PWD##*/}" + workon "${PWD##*/}" } From 081026359e84736a4c36f4c6ec7ddc744a2fd370 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 19 Nov 2024 23:58:13 +0200 Subject: [PATCH 3/8] fixing plugins/available/thefuck.plugin.bash --- clean_files.txt | 1 + plugins/available/thefuck.plugin.bash | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index f42ffea7a9..62d2762da5 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -131,6 +131,7 @@ plugins/available/python.plugin.bash plugins/available/rbenv.plugin.bash plugins/available/ruby.plugin.bash plugins/available/textmate.plugin.bash +plugins/available/thefuck.plugin.bash plugins/available/todo.plugin.bash plugins/available/url.plugin.bash plugins/available/virtualenv.plugin.bash diff --git a/plugins/available/thefuck.plugin.bash b/plugins/available/thefuck.plugin.bash index 242a77df22..3427e7c58e 100644 --- a/plugins/available/thefuck.plugin.bash +++ b/plugins/available/thefuck.plugin.bash @@ -1,9 +1,10 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Initialization for fuck' # https://github.com/nvbn/thefuck if _command_exists thefuck; then - # shellcheck disable=SC2046 - eval $(thefuck --alias) + # shellcheck disable=SC2046 + eval $(thefuck --alias) fi From d933bb45c35014bf6427bbf1878333901af94989 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Wed, 20 Nov 2024 00:01:06 +0200 Subject: [PATCH 4/8] fixing plugins/available/sudo.plugin.bash --- clean_files.txt | 1 + plugins/available/sudo.plugin.bash | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 62d2762da5..011cb9b8ab 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -130,6 +130,7 @@ plugins/available/pyenv.plugin.bash plugins/available/python.plugin.bash plugins/available/rbenv.plugin.bash plugins/available/ruby.plugin.bash +plugins/available/sudo.plugin.bash plugins/available/textmate.plugin.bash plugins/available/thefuck.plugin.bash plugins/available/todo.plugin.bash diff --git a/plugins/available/sudo.plugin.bash b/plugins/available/sudo.plugin.bash index eb155daa04..6451eb74c1 100644 --- a/plugins/available/sudo.plugin.bash +++ b/plugins/available/sudo.plugin.bash @@ -1,22 +1,23 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Toggle sudo at the beginning of the current or the previous command by hitting the ESC key twice' function sudo-command-line() { - about "toggle sudo at the beginning of the current or the previous command by hitting the ESC key twice" - group "sudo" + about "toggle sudo at the beginning of the current or the previous command by hitting the ESC key twice" + group "sudo" - [[ ${#READLINE_LINE} -eq 0 ]] && READLINE_LINE=$(fc -l -n -1 | xargs) - if [[ $READLINE_LINE == sudo\ * ]]; then - READLINE_LINE="${READLINE_LINE#sudo }" - else - READLINE_LINE="sudo $READLINE_LINE" - fi - READLINE_POINT=${#READLINE_LINE} + [[ ${#READLINE_LINE} -eq 0 ]] && READLINE_LINE=$(fc -l -n -1 | xargs) + if [[ $READLINE_LINE == sudo\ * ]]; then + READLINE_LINE="${READLINE_LINE#sudo }" + else + READLINE_LINE="sudo $READLINE_LINE" + fi + READLINE_POINT=${#READLINE_LINE} } # Define shortcut keys: [Esc] [Esc] # Readline library requires bash version 4 or later -if [ "${BASH_VERSINFO}" -ge 4 ]; then - bind -x '"\e\e": sudo-command-line' +if [ "${BASH_VERSINFO[0]}" -ge 4 ]; then + bind -x '"\e\e": sudo-command-line' fi From 3678e366faa4d07ee9005deeace6e3f48ec0da08 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 24 Dec 2024 09:56:58 +0200 Subject: [PATCH 5/8] also check on latest ubuntu --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9154a0bc7..c5d869c6da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: bats-test: strategy: matrix: - os: [ubuntu-20.04, ubuntu-22.04, macos-14, macos-15] + os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, macos-14, macos-15] runs-on: ${{ matrix.os }} From 550d68d3f1e97135c2e3c6b7baa5a4de7295b1d5 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 24 Dec 2024 12:11:24 +0200 Subject: [PATCH 6/8] some compgen tricks are just too complex to write "by the rules" --- clean_files.txt | 1 + .../available/capistrano.completion.bash | 33 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 011cb9b8ab..f33e4fbc9e 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -40,6 +40,7 @@ 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 diff --git a/completion/available/capistrano.completion.bash b/completion/available/capistrano.completion.bash index d5fda06fa5..d84a5bd2dd 100644 --- a/completion/available/capistrano.completion.bash +++ b/completion/available/capistrano.completion.bash @@ -1,24 +1,25 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # Bash completion support for Capistrano. export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/} _capcomplete() { - if [ -f Capfile ]; then - recent=`ls -t .cap_tasks~ Capfile **/*.cap 2> /dev/null | head -n 1` - if [[ $recent != '.cap_tasks~' ]]; then - cap --version | grep 'Capistrano v2.' > /dev/null - if [ $? -eq 0 ]; then - # Capistrano 2.x - cap --tool --verbose --tasks | cut -d " " -f 2 > .cap_tasks~ - else - # Capistrano 3.x - cap --all --tasks | cut -d " " -f 2 > .cap_tasks~ - fi - fi - COMPREPLY=($(compgen -W "`cat .cap_tasks~`" -- ${COMP_WORDS[COMP_CWORD]})) - return 0 - fi + if [ -f Capfile ]; then + # shellcheck disable=SC2012 + recent=$(ls -t .cap_tasks~ Capfile ./**/*.cap 2> /dev/null | head -n 1) + if [[ $recent != '.cap_tasks~' ]]; then + if cap --version | grep -q 'Capistrano v2.'; then + # Capistrano 2.x + cap --tool --verbose --tasks | cut -d " " -f 2 > .cap_tasks~ + else + # Capistrano 3.x + cap --all --tasks | cut -d " " -f 2 > .cap_tasks~ + fi + fi + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$(cat .cap_tasks~)" -- "${COMP_WORDS[COMP_CWORD]}")) + return 0 + fi } complete -o default -o nospace -F _capcomplete cap From cedcac2de4209958e5307431d9d23b8628f04f91 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 24 Dec 2024 12:14:22 +0200 Subject: [PATCH 7/8] shfmt and shellcheck, dirs.completion is ready --- clean_files.txt | 1 + completion/available/dirs.completion.bash | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index f33e4fbc9e..9f3802b46d 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -46,6 +46,7 @@ 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-machine.completion.bash diff --git a/completion/available/dirs.completion.bash b/completion/available/dirs.completion.bash index ba18db3241..c6e01155d6 100644 --- a/completion/available/dirs.completion.bash +++ b/completion/available/dirs.completion.bash @@ -1,15 +1,16 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # Bash completion support for the 'dirs' plugin (commands G, R). _dirs-complete() { - local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}" + local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}" - # parse all defined shortcuts from ~/.dirs - if [ -r "$HOME/.dirs" ]; then - COMPREPLY=($(compgen -W "$(grep -v '^#' ~/.dirs | sed -e 's/\(.*\)=.*/\1/')" -- ${CURRENT_PROMPT}) ) - fi + # parse all defined shortcuts from ~/.dirs + if [ -r "$HOME/.dirs" ]; then + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$(grep -v '^#' ~/.dirs | sed -e 's/\(.*\)=.*/\1/')" -- "${CURRENT_PROMPT}")) + fi - return 0 + return 0 } complete -o default -o nospace -F _dirs-complete G R From 0a92d76c4ca2b0a65c2e4d101c46718fb380d87e Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 24 Dec 2024 12:31:45 +0200 Subject: [PATCH 8/8] shfmt and shellcheck, docker-compose.completion is ready --- clean_files.txt | 1 + .../available/docker-compose.completion.bash | 226 ++++++++---------- 2 files changed, 103 insertions(+), 124 deletions(-) mode change 100755 => 100644 completion/available/docker-compose.completion.bash diff --git a/clean_files.txt b/clean_files.txt index 9f3802b46d..02bdfe588d 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -49,6 +49,7 @@ 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 diff --git a/completion/available/docker-compose.completion.bash b/completion/available/docker-compose.completion.bash old mode 100755 new mode 100644 index 1102f5d97e..57d414fd5a --- a/completion/available/docker-compose.completion.bash +++ b/completion/available/docker-compose.completion.bash @@ -1,4 +1,5 @@ -#!/bin/bash +# shellcheck shell=bash +# shellcheck disable=SC2207 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,13 +36,13 @@ __docker_compose_previous_extglob_setting=$(shopt -p extglob) shopt -s extglob __docker_compose_q() { - docker-compose 2>/dev/null "${top_level_options[@]}" "$@" + docker-compose 2> /dev/null "${top_level_options[@]}" "$@" } # Transforms a multiline list of strings into a single line string # with the words separated by "|". __docker_compose_to_alternatives() { - local parts=( $1 ) + local parts=("$1") local IFS='|' echo "${parts[*]}" } @@ -49,7 +50,8 @@ __docker_compose_to_alternatives() { # Transforms a multiline list of options into an extglob pattern # suitable for use in case statements. __docker_compose_to_extglob() { - local extglob=$( __docker_compose_to_alternatives "$1" ) + local extglob + extglob=$(__docker_compose_to_alternatives "$1") echo "@($extglob)" } @@ -57,8 +59,8 @@ __docker_compose_to_extglob() { # the commandline. The option may be a pattern, e.g. `--force|-f`. __docker_compose_has_option() { local pattern="$1" - for (( i=2; i < $cword; ++i)); do - if [[ ${words[$i]} =~ ^($pattern)$ ]] ; then + for ((i = 2; i < cword; ++i)); do + if [[ ${words[$i]} =~ ^($pattern)$ ]]; then return 0 fi done @@ -69,34 +71,33 @@ __docker_compose_has_option() { # which matches the extglob passed in as an argument. # This function is needed for key-specific completions. __docker_compose_map_key_of_current_option() { - local glob="$1" + local glob="$1" - local key glob_pos - if [ "$cur" = "=" ] ; then # key= case - key="$prev" - glob_pos=$((cword - 2)) - elif [[ $cur == *=* ]] ; then # key=value case (OSX) - key=${cur%=*} - glob_pos=$((cword - 1)) - elif [ "$prev" = "=" ] ; then - key=${words[$cword - 2]} # key=value case - glob_pos=$((cword - 3)) - else - return - fi + local key glob_pos + if [ "$cur" = "=" ]; then # key= case + key="$prev" + glob_pos=$((cword - 2)) + elif [[ $cur == *=* ]]; then # key=value case (OSX) + key=${cur%=*} + glob_pos=$((cword - 1)) + elif [ "$prev" = "=" ]; then + key=${words[$cword - 2]} # key=value case + glob_pos=$((cword - 3)) + else + return + fi - [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax + [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax - [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key" + [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key" } # suppress trailing whitespace __docker_compose_nospace() { # compopt is not available in ancient bash versions - type compopt &>/dev/null && compopt -o nospace + type compopt &> /dev/null && compopt -o nospace } - # Outputs a list of all defined services, regardless of their running state. # Arguments for `docker-compose ps` may be passed in order to filter the service list, # e.g. `status=running`. @@ -108,31 +109,31 @@ __docker_compose_services() { # Arguments for `docker-compose ps` may be passed in order to filter the service list, # see `__docker_compose_services`. __docker_compose_complete_services() { - COMPREPLY=( $(compgen -W "$(__docker_compose_services "$@")" -- "$cur") ) + COMPREPLY=($(compgen -W "$(__docker_compose_services "$@")" -- "$cur")) } # The services for which at least one running container exists __docker_compose_complete_running_services() { - local names=$(__docker_compose_services --filter status=running) - COMPREPLY=( $(compgen -W "$names" -- "$cur") ) + local names + names=$(__docker_compose_services --filter status=running) + COMPREPLY=($(compgen -W "$names" -- "$cur")) } - _docker_compose_build() { case "$prev" in --build-arg) - COMPREPLY=( $( compgen -e -- "$cur" ) ) + COMPREPLY=($(compgen -e -- "$cur")) __docker_compose_nospace return ;; - --memory|-m) + --memory | -m) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--build-arg --compress --force-rm --help --memory -m --no-cache --no-rm --pull --parallel -q --quiet" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--build-arg --compress --force-rm --help --memory -m --no-cache --no-rm --pull --parallel -q --quiet" -- "$cur")) ;; *) __docker_compose_complete_services --filter source=build @@ -140,39 +141,36 @@ _docker_compose_build() { esac } - _docker_compose_bundle() { case "$prev" in - --output|-o) + --output | -o) _filedir return ;; esac - COMPREPLY=( $( compgen -W "--push-images --help --output -o" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--push-images --help --output -o" -- "$cur")) } - _docker_compose_config() { case "$prev" in --hash) - if [[ $cur == \\* ]] ; then - COMPREPLY=( '\*' ) + if [[ $cur == \\* ]]; then + COMPREPLY=('\*') else - COMPREPLY=( $(compgen -W "$(__docker_compose_services) \\\* " -- "$cur") ) + COMPREPLY=($(compgen -W "$(__docker_compose_services) \\\* " -- "$cur")) fi return ;; esac - COMPREPLY=( $( compgen -W "--hash --help --quiet -q --resolve-image-digests --services --volumes" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--hash --help --quiet -q --resolve-image-digests --services --volumes" -- "$cur")) } - _docker_compose_create() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--build --force-recreate --help --no-build --no-recreate" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--build --force-recreate --help --no-build --no-recreate" -- "$cur")) ;; *) __docker_compose_complete_services @@ -180,60 +178,57 @@ _docker_compose_create() { esac } - _docker_compose_docker_compose() { case "$prev" in - --tlscacert|--tlscert|--tlskey) + --tlscacert | --tlscert | --tlskey) _filedir return ;; - --file|-f) + --file | -f) _filedir "y?(a)ml" return ;; --log-level) - COMPREPLY=( $( compgen -W "debug info warning error critical" -- "$cur" ) ) + COMPREPLY=($(compgen -W "debug info warning error critical" -- "$cur")) return ;; --project-directory) _filedir -d return ;; - $(__docker_compose_to_extglob "$daemon_options_with_args") ) + "$(__docker_compose_to_extglob "$daemon_options_with_args")") return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "$daemon_boolean_options $daemon_options_with_args $top_level_options_with_args --help -h --no-ansi --verbose --version -v" -- "$cur" ) ) + COMPREPLY=($(compgen -W "$daemon_boolean_options $daemon_options_with_args $top_level_options_with_args --help -h --no-ansi --verbose --version -v" -- "$cur")) ;; *) - COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) ) + COMPREPLY=($(compgen -W "${commands[*]}" -- "$cur")) ;; esac } - _docker_compose_down() { case "$prev" in --rmi) - COMPREPLY=( $( compgen -W "all local" -- "$cur" ) ) + COMPREPLY=($(compgen -W "all local" -- "$cur")) return ;; - --timeout|-t) + --timeout | -t) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --rmi --timeout -t --volumes -v --remove-orphans" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --rmi --timeout -t --volumes -v --remove-orphans" -- "$cur")) ;; esac } - _docker_compose_events() { case "$prev" in --json) @@ -243,7 +238,7 @@ _docker_compose_events() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --json" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --json" -- "$cur")) ;; *) __docker_compose_complete_services @@ -251,17 +246,16 @@ _docker_compose_events() { esac } - _docker_compose_exec() { case "$prev" in - --index|--user|-u|--workdir|-w) + --index | --user | -u | --workdir | -w) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "-d --detach --help --index --privileged -T --user -u --workdir -w" -- "$cur" ) ) + COMPREPLY=($(compgen -W "-d --detach --help --index --privileged -T --user -u --workdir -w" -- "$cur")) ;; *) __docker_compose_complete_running_services @@ -269,15 +263,14 @@ _docker_compose_exec() { esac } - _docker_compose_help() { - COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) ) + COMPREPLY=($(compgen -W "${commands[*]}" -- "$cur")) } _docker_compose_images() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --quiet -q" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --quiet -q" -- "$cur")) ;; *) __docker_compose_complete_services @@ -288,14 +281,14 @@ _docker_compose_images() { _docker_compose_kill() { case "$prev" in -s) - COMPREPLY=( $( compgen -W "SIGHUP SIGINT SIGKILL SIGUSR1 SIGUSR2" -- "$(echo $cur | tr '[:lower:]' '[:upper:]')" ) ) + COMPREPLY=($(compgen -W "SIGHUP SIGINT SIGKILL SIGUSR1 SIGUSR2" -- "$(echo "$cur" | tr '[:lower:]' '[:upper:]')")) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help -s" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help -s" -- "$cur")) ;; *) __docker_compose_complete_running_services @@ -303,7 +296,6 @@ _docker_compose_kill() { esac } - _docker_compose_logs() { case "$prev" in --tail) @@ -313,7 +305,7 @@ _docker_compose_logs() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--follow -f --help --no-color --tail --timestamps -t" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--follow -f --help --no-color --tail --timestamps -t" -- "$cur")) ;; *) __docker_compose_complete_services @@ -321,11 +313,10 @@ _docker_compose_logs() { esac } - _docker_compose_pause() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help" -- "$cur")) ;; *) __docker_compose_complete_running_services @@ -333,21 +324,20 @@ _docker_compose_pause() { esac } - _docker_compose_port() { case "$prev" in --protocol) - COMPREPLY=( $( compgen -W "tcp udp" -- "$cur" ) ) - return; + COMPREPLY=($(compgen -W "tcp udp" -- "$cur")) + return ;; --index) - return; + return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --index --protocol" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --index --protocol" -- "$cur")) ;; *) __docker_compose_complete_services @@ -355,31 +345,31 @@ _docker_compose_port() { esac } - _docker_compose_ps() { - local key=$(__docker_compose_map_key_of_current_option '--filter') + local key + key=$(__docker_compose_map_key_of_current_option '--filter') case "$key" in source) - COMPREPLY=( $( compgen -W "build image" -- "${cur##*=}" ) ) + COMPREPLY=($(compgen -W "build image" -- "${cur##*=}")) return ;; status) - COMPREPLY=( $( compgen -W "paused restarting running stopped" -- "${cur##*=}" ) ) + COMPREPLY=($(compgen -W "paused restarting running stopped" -- "${cur##*=}")) return ;; esac case "$prev" in --filter) - COMPREPLY=( $( compgen -W "source status" -S "=" -- "$cur" ) ) + COMPREPLY=($(compgen -W "source status" -S "=" -- "$cur")) __docker_compose_nospace - return; + return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--all -a --filter --help --quiet -q --services" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--all -a --filter --help --quiet -q --services" -- "$cur")) ;; *) __docker_compose_complete_services @@ -387,11 +377,10 @@ _docker_compose_ps() { esac } - _docker_compose_pull() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --ignore-pull-failures --include-deps --no-parallel --quiet -q" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --ignore-pull-failures --include-deps --no-parallel --quiet -q" -- "$cur")) ;; *) __docker_compose_complete_services --filter source=image @@ -399,11 +388,10 @@ _docker_compose_pull() { esac } - _docker_compose_push() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --ignore-push-failures" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --ignore-push-failures" -- "$cur")) ;; *) __docker_compose_complete_services @@ -411,17 +399,16 @@ _docker_compose_push() { esac } - _docker_compose_restart() { case "$prev" in - --timeout|-t) + --timeout | -t) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --timeout -t" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --timeout -t" -- "$cur")) ;; *) __docker_compose_complete_running_services @@ -429,14 +416,13 @@ _docker_compose_restart() { esac } - _docker_compose_rm() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--force -f --help --stop -s -v" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--force -f --help --stop -s -v" -- "$cur")) ;; *) - if __docker_compose_has_option "--stop|-s" ; then + if __docker_compose_has_option "--stop|-s"; then __docker_compose_complete_services else __docker_compose_complete_services --filter status=stopped @@ -445,22 +431,21 @@ _docker_compose_rm() { esac } - _docker_compose_run() { case "$prev" in -e) - COMPREPLY=( $( compgen -e -- "$cur" ) ) + COMPREPLY=($(compgen -e -- "$cur")) __docker_compose_nospace return ;; - --entrypoint|--label|-l|--name|--user|-u|--volume|-v|--workdir|-w) + --entrypoint | --label | -l | --name | --user | -u | --volume | -v | --workdir | -w) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--detach -d --entrypoint -e --help --label -l --name --no-deps --publish -p --rm --service-ports -T --use-aliases --user -u --volume -v --workdir -w" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--detach -d --entrypoint -e --help --label -l --name --no-deps --publish -p --rm --service-ports -T --use-aliases --user -u --volume -v --workdir -w" -- "$cur")) ;; *) __docker_compose_complete_services @@ -468,34 +453,32 @@ _docker_compose_run() { esac } - _docker_compose_scale() { case "$prev" in =) COMPREPLY=("$cur") return ;; - --timeout|-t) + --timeout | -t) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --timeout -t" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --timeout -t" -- "$cur")) ;; *) - COMPREPLY=( $(compgen -S "=" -W "$(__docker_compose_services)" -- "$cur") ) + COMPREPLY=($(compgen -S "=" -W "$(__docker_compose_services)" -- "$cur")) __docker_compose_nospace ;; esac } - _docker_compose_start() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help" -- "$cur")) ;; *) __docker_compose_complete_services --filter status=stopped @@ -503,17 +486,16 @@ _docker_compose_start() { esac } - _docker_compose_stop() { case "$prev" in - --timeout|-t) + --timeout | -t) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --timeout -t" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --timeout -t" -- "$cur")) ;; *) __docker_compose_complete_running_services @@ -521,11 +503,10 @@ _docker_compose_stop() { esac } - _docker_compose_top() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help" -- "$cur")) ;; *) __docker_compose_complete_running_services @@ -533,11 +514,10 @@ _docker_compose_top() { esac } - _docker_compose_unpause() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help" -- "$cur")) ;; *) __docker_compose_complete_services --filter status=paused @@ -545,7 +525,6 @@ _docker_compose_unpause() { esac } - _docker_compose_up() { case "$prev" in =) @@ -557,18 +536,18 @@ _docker_compose_up() { return ;; --scale) - COMPREPLY=( $(compgen -S "=" -W "$(__docker_compose_services)" -- "$cur") ) + COMPREPLY=($(compgen -S "=" -W "$(__docker_compose_services)" -- "$cur")) __docker_compose_nospace return ;; - --timeout|-t) + --timeout | -t) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--abort-on-container-exit --always-recreate-deps --build -d --detach --exit-code-from --force-recreate --help --no-build --no-color --no-deps --no-recreate --no-start --renew-anon-volumes -V --remove-orphans --scale --timeout -t" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--abort-on-container-exit --always-recreate-deps --build -d --detach --exit-code-from --force-recreate --help --no-build --no-color --no-deps --no-recreate --no-start --renew-anon-volumes -V --remove-orphans --scale --timeout -t" -- "$cur")) ;; *) __docker_compose_complete_services @@ -576,18 +555,17 @@ _docker_compose_up() { esac } - _docker_compose_version() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--short" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--short" -- "$cur")) ;; esac } - _docker_compose() { - local previous_extglob_setting=$(shopt -p extglob) + local previous_extglob_setting + previous_extglob_setting=$(shopt -p extglob) shopt -s extglob local commands=( @@ -651,32 +629,32 @@ _docker_compose() { local top_level_options=() local counter=1 - while [ $counter -lt $cword ]; do + while [ $counter -lt "$cword" ]; do case "${words[$counter]}" in - $(__docker_compose_to_extglob "$daemon_boolean_options") ) + "$(__docker_compose_to_extglob "$daemon_boolean_options")") local opt=${words[counter]} - top_level_options+=($opt) + top_level_options+=("$opt") ;; - $(__docker_compose_to_extglob "$daemon_options_with_args") ) + "$(__docker_compose_to_extglob "$daemon_options_with_args")") local opt=${words[counter]} local arg=${words[++counter]} - top_level_options+=($opt $arg) + top_level_options+=("$opt" "$arg") ;; - $(__docker_compose_to_extglob "$top_level_options_with_args") ) - (( counter++ )) - ;; - -*) + "$(__docker_compose_to_extglob "$top_level_options_with_args")") + ((counter++)) ;; + -*) ;; + *) command="${words[$counter]}" break ;; esac - (( counter++ )) + ((counter++)) done local completions_func=_docker_compose_${command//-/_} - _is_function $completions_func && $completions_func + _is_function "$completions_func" && $completions_func eval "$previous_extglob_setting" return 0