Skip to content

Commit

Permalink
Merge branch 'master' into ira/pre-commit-cleanup
Browse files Browse the repository at this point in the history
* master: (41 commits)
  no need to test so many versions, just the newest and oldest, I think?
  First attempt: just a naiive upgrade of BATS
  you go "quote-TOAH" on that thang!
  ironing this odd lint problem
  ironing this odd lint problem
  Allow setting git current user and add a default icon
  shfmt and shellcheck, docker-compose.completion is ready
  shfmt and shellcheck, dirs.completion is ready
  some compgen tricks are just too complex to write "by the rules"
  also check on latest ubuntu
  fixing plugins/available/sudo.plugin.bash
  fixing plugins/available/thefuck.plugin.bash
  fixing plugins/available/virtualenv.plugin.bash
  fixing plugins/available/z_autoenv.plugin.bash
  fixing bundler
  fixing salt
  fixing gradle
  fixing docker-compose.plugin.bash
  I guess this needs to be fixed to pass the tests...
  Start checking one newer macos, the old versions are getting irrelevant
  ...
  • Loading branch information
Ira Abramov committed Jan 22, 2025
2 parents 2279401 + 0cfc448 commit a6cdab2
Show file tree
Hide file tree
Showing 47 changed files with 2,443 additions and 2,242 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
bats-test:
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-22.04, macos-12, macos-11]
os: [ubuntu-20.04, ubuntu-24.04, macos-14]

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -62,3 +62,21 @@ jobs:
run: python3 -m pip install -r test/lint-requirements.txt
- name: Run lint
run: ./lint_clean_files.sh

lint-differential:
runs-on: ubuntu-latest

permissions:
security-events: write

steps:
- name: Repository checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- id: ShellCheck
name: Differential ShellCheck
uses: redhat-plumbers-in-action/differential-shellcheck@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[submodule "test_lib/bats-core"]
path = test_lib/bats-core
url = https://github.com/bats-core/bats-core
branch = tags/v1.2.0
branch = tags/v1.9.0
[submodule "test_lib/bats-support"]
path = test_lib/bats-support
url = https://github.com/bats-core/bats-support
branch = tags/v0.3.0
[submodule "test_lib/bats-assert"]
path = test_lib/bats-assert
url = https://github.com/bats-core/bats-assert
branch = tags/v2.0.0
branch = tags/v2.1.0
[submodule "test_lib/bats-file"]
path = test_lib/bats-file
url = https://github.com/bats-core/bats-file
branch = tags/v0.3.0
branch = tags/v0.4.0
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ repos:
- id: git-check # Configure in .gitattributes
- id: shellcheck
- id: shfmt
exclude: ".bats$"
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.7
hooks:
Expand Down
18 changes: 12 additions & 6 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ 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
Expand Down Expand Up @@ -75,6 +79,7 @@ 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
Expand All @@ -95,12 +100,14 @@ plugins/available/cmd-returned-notify.plugin.bash
plugins/available/colors.plugin.bash
plugins/available/direnv.plugin.bash
plugins/available/dirs.plugin.bash
plugins/available/docker-compose.plugin.bash
plugins/available/docker-machine.plugin.bash
plugins/available/gif.plugin.bash
plugins/available/git-subrepo.plugin.bash
plugins/available/git.plugin.bash
plugins/available/go.plugin.bash
plugins/available/goenv.plugin.bash
plugins/available/gradle.plugin.bash
plugins/available/history-eternal.plugin.bash
plugins/available/history-search.plugin.bash
plugins/available/history-substring-search.plugin.bash
Expand All @@ -126,18 +133,16 @@ 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
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

# tests
#
test/completion/aliases.completion.bats
test/run
test/test_helper.bash

# themes
#
themes/90210
Expand All @@ -159,6 +164,7 @@ themes/easy
themes/elixr
themes/essential
themes/githelpers.theme.bash
themes/gitline
themes/inretio
themes/lambda
themes/modern
Expand Down
31 changes: 18 additions & 13 deletions completion/available/bundler.completion.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#! bash
# shellcheck shell=bash
# shellcheck disable=SC2207
# bash completion for the `bundle` command.
#
# Copyright (c) 2008 Daniel Luz
Expand Down Expand Up @@ -146,6 +147,7 @@ __bundle() {
options+=(local. mirror.)
# Override $IFS for completion to work
local IFS=$'\n'
# shellcheck disable=SC2016
COMPREPLY=($(compgen -W '${options[@]}' -- "$cur"))
return
;;
Expand All @@ -160,19 +162,21 @@ __bundle() {
exec)
if [[ $COMP_CWORD -eq $bundle_command_index ]]; then
# Figure out Bundler's binaries dir
local bundler_bin=$(__bundle_exec_ruby 'puts Bundler.bundle_path + "bin"')
local bundler_bin
bundler_bin=$(__bundle_exec_ruby 'puts Bundler.bundle_path + "bin"')
if [[ -d $bundler_bin ]]; then
local binaries=("$bundler_bin"/*)
local binaries
binaries=("$bundler_bin"/*)
# If there are binaries, strip directory name and use them
[[ -f "$binaries" ]] && options="${binaries[@]##*/}"
[[ -f "${binaries[0]}" ]] && options=("${binaries[@]##*/}")
else
# No binaries found; use full command completion
COMPREPLY=($(compgen -c -- "$cur"))
return
fi
else
local _RUBY_COMMAND_PREFIX=("${bundle_bin[@]}" exec)
_command_offset $bundle_command_index
_command_offset "$bundle_command_index"
return
fi
;;
Expand All @@ -183,7 +187,7 @@ __bundle() {
return
;;
-t | --test)
options="minitest rspec"
options=("minitest" "rspec")
;;
esac
;;
Expand All @@ -201,7 +205,7 @@ __bundle() {
viz)
case $prev in
-F | --format)
options="dot jpg png svg"
options=("dot" "jpg" "png" "svg")
;;
-W | --without)
__bundle_complete_groups
Expand All @@ -216,7 +220,7 @@ __bundle() {

__bundle_get_command() {
local i
for ((i = 1; i < $COMP_CWORD; ++i)); do
for ((i = 1; i < COMP_CWORD; ++i)); do
local arg=${COMP_WORDS[$i]}

case $arg in
Expand Down Expand Up @@ -248,7 +252,8 @@ __bundle_complete_groups() {
local cur_group=${cur##*[ :]}
# All groups written before
local prefix=${cur%"$cur_group"}
local groups=$(__bundle_exec_ruby 'puts Bundler.definition.dependencies.map(&:groups).reduce(:|).map(&:to_s)')
local groups
groups=$(__bundle_exec_ruby 'puts Bundler.definition.dependencies.map(&:groups).reduce(:|).map(&:to_s)')
if [[ ! $groups ]]; then
COMPREPLY=()
return
Expand All @@ -269,7 +274,7 @@ __bundle_complete_groups() {
# Runs a Ruby script with Bundler loaded.
# Results may be cached.
__bundle_exec_ruby() {
local bundle_bin=(${bundle_bin[@]:-bundle})
local bundle_bin=("${bundle_bin[@]:-bundle}")
# Lockfile is inferred here, and might not be correct (for example, when
# running on a subdirectory). However, a wrong file path won't be a
# cadastrophic mistake; it just means the cache won't be invalidated when
Expand All @@ -286,10 +291,10 @@ __bundle_exec_ruby() {
$(head -n 1 -- "$cachefile" 2> /dev/null) = "$cache_id_line" ]]; then
tail -n +2 -- "$cachefile"
else
local output=$("${bundle_bin[@]}" exec ruby -e "$@" 2> /dev/null)
if [[ $? -eq 0 ]]; then
local output
if output=$("${bundle_bin[@]}" exec ruby -e "$@" 2> /dev/null); then
(mkdir -p -- "$cachedir" \
&& echo "$cache_id_line"$'\n'"$output" > $cachefile) 2> /dev/null
&& echo "$cache_id_line"$'\n'"$output" > "$cachefile") 2> /dev/null
echo "$output"
fi
fi
Expand Down
11 changes: 6 additions & 5 deletions completion/available/capistrano.completion.bash
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#!/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)
# shellcheck disable=SC2012
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
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
COMPREPLY=($(compgen -W "$(cat .cap_tasks~)" -- ${COMP_WORDS[COMP_CWORD]}))
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$(cat .cap_tasks~)" -- "${COMP_WORDS[COMP_CWORD]}"))
return 0
fi
}
Expand Down
5 changes: 3 additions & 2 deletions completion/available/dirs.completion.bash
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/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]}"

# parse all defined shortcuts from ~/.dirs
if [ -r "$HOME/.dirs" ]; then
COMPREPLY=($(compgen -W "$(grep -v '^#' ~/.dirs | sed -e 's/\(.*\)=.*/\1/')" -- ${CURRENT_PROMPT}))
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$(grep -v '^#' ~/.dirs | sed -e 's/\(.*\)=.*/\1/')" -- "${CURRENT_PROMPT}"))
fi

return 0
Expand Down
38 changes: 22 additions & 16 deletions completion/available/docker-compose.completion.bash
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck shell=bash
# shellcheck disable=SC2207
#

# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -41,23 +42,24 @@ __docker_compose_q() {
# 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[*]}"
}

# 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)"
}

# Determines whether the option passed as the first argument exist on
# 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
for ((i = 2; i < cword; ++i)); do
if [[ ${words[$i]} =~ ^($pattern)$ ]]; then
return 0
fi
Expand Down Expand Up @@ -112,7 +114,8 @@ __docker_compose_complete_services() {

# The services for which at least one running container exists
__docker_compose_complete_running_services() {
local names=$(__docker_compose_services --filter status=running)
local names
names=$(__docker_compose_services --filter status=running)
COMPREPLY=($(compgen -W "$names" -- "$cur"))
}

Expand Down Expand Up @@ -193,7 +196,7 @@ _docker_compose_docker_compose() {
_filedir -d
return
;;
$(__docker_compose_to_extglob "$daemon_options_with_args"))
"$(__docker_compose_to_extglob "$daemon_options_with_args")")
return
;;
esac
Expand Down Expand Up @@ -278,7 +281,7 @@ _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
Expand Down Expand Up @@ -343,7 +346,8 @@ _docker_compose_port() {
}

_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##*=}"))
Expand Down Expand Up @@ -560,7 +564,8 @@ _docker_compose_version() {
}

_docker_compose() {
local previous_extglob_setting=$(shopt -p extglob)
local previous_extglob_setting
previous_extglob_setting=$(shopt -p extglob)
shopt -s extglob

local commands=(
Expand Down Expand Up @@ -624,21 +629,22 @@ _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"))
"$(__docker_compose_to_extglob "$top_level_options_with_args")")
((counter++))
;;
-*) ;;

*)
command="${words[$counter]}"
break
Expand All @@ -648,7 +654,7 @@ _docker_compose() {
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
Expand Down
Loading

0 comments on commit a6cdab2

Please sign in to comment.