Skip to content

Commit

Permalink
Merge pull request #2282 from Bash-it/ira/cleanup4
Browse files Browse the repository at this point in the history
  • Loading branch information
seefood authored Jan 29, 2025
2 parents 14ee27c + 0f98b91 commit c4baa6e
Show file tree
Hide file tree
Showing 24 changed files with 893 additions and 815 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ repos:
hooks:
- id: git-check # Configure in .gitattributes
- id: shellcheck
files: "\\.(bash)$"
- id: shfmt
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.7
Expand All @@ -38,7 +39,7 @@ repos:
name: Check .bash files against bash-it requirements
entry: ./hooks/dot-bash.sh
language: system
files: "\\.ba[ts][sh]$"
files: "\\.(bash)$"
types: [file]
- id: clean-files-txt
name: Check that clean_files.txt is sorted alphabetically.
Expand Down
7 changes: 7 additions & 0 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,25 @@ plugins/available/direnv.plugin.bash
plugins/available/dirs.plugin.bash
plugins/available/docker-compose.plugin.bash
plugins/available/docker-machine.plugin.bash
plugins/available/fasd.plugin.bash
plugins/available/fzf.plugin.bash
plugins/available/gif.plugin.bash
plugins/available/git-subrepo.plugin.bash
plugins/available/git.plugin.bash
plugins/available/gitstatus.plugin.bash
plugins/available/go.plugin.bash
plugins/available/goenv.plugin.bash
plugins/available/gradle.plugin.bash
plugins/available/hg.plugin.bash
plugins/available/history-eternal.plugin.bash
plugins/available/history-search.plugin.bash
plugins/available/history-substring-search.plugin.bash
plugins/available/history.plugin.bash
plugins/available/hub.plugin.bash
plugins/available/java.plugin.bash
plugins/available/javascript.plugin.bash
plugins/available/jekyll.plugin.bash
plugins/available/jenv.plugin.bash
plugins/available/jgitflow.plugin.bash
plugins/available/jump.plugin.bash
plugins/available/latex.plugin.bash
Expand All @@ -125,6 +131,7 @@ plugins/available/node.plugin.bash
plugins/available/nodenv.plugin.bash
plugins/available/osx-timemachine.plugin.bash
plugins/available/osx.plugin.bash
plugins/available/pack.plugin.bash
plugins/available/percol.plugin.bash
plugins/available/plenv.plugin.bash
plugins/available/postgres.plugin.bash
Expand Down
17 changes: 9 additions & 8 deletions completion/available/sdkman.completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ function _sdkman_complete() {

COMPREPLY=()

local line
if [ "$COMP_CWORD" -eq 1 ]; then
mapfile -t COMPREPLY < <(compgen -W "install uninstall rm list ls use default home env current upgrade ug version broadcast help offline selfupdate update flush" -- "${COMP_WORDS[COMP_CWORD]}")
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "install uninstall rm list ls use default home env current upgrade ug version broadcast help offline selfupdate update flush" -- "${COMP_WORDS[COMP_CWORD]}")
elif [ "$COMP_CWORD" -eq 2 ]; then
case "${COMP_WORDS[COMP_CWORD - 1]}" in
"install" | "i" | "uninstall" | "rm" | "list" | "ls" | "use" | "u" | "default" | "d" | "home" | "h" | "current" | "c" | "upgrade" | "ug")
CANDIDATES="${SDKMAN_CANDIDATES_CSV//,/${IFS:0:1}}"
mapfile -t COMPREPLY < <(compgen -W "$CANDIDATES" -- "${COMP_WORDS[COMP_CWORD]}")
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "$CANDIDATES" -- "${COMP_WORDS[COMP_CWORD]}")
;;
"env")
mapfile -t COMPREPLY < <(compgen -W "init" -- "${COMP_WORDS[COMP_CWORD]}")
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "init" -- "${COMP_WORDS[COMP_CWORD]}")
;;
"offline")
mapfile -t COMPREPLY < <(compgen -W "enable disable" -- "${COMP_WORDS[COMP_CWORD]}")
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "enable disable" -- "${COMP_WORDS[COMP_CWORD]}")
;;
"selfupdate")
mapfile -t COMPREPLY < <(compgen -W "force" -- "${COMP_WORDS[COMP_CWORD]}")
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "force" -- "${COMP_WORDS[COMP_CWORD]}")
;;
"flush")
mapfile -t COMPREPLY < <(compgen -W "archives tmp broadcast version" -- "${COMP_WORDS[COMP_CWORD]}")
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "archives tmp broadcast version" -- "${COMP_WORDS[COMP_CWORD]}")
;;
*) ;;

Expand All @@ -34,11 +35,11 @@ function _sdkman_complete() {
case "${COMP_WORDS[COMP_CWORD - 2]}" in
"uninstall" | "rm" | "use" | "u" | "default" | "d" | "home" | "h")
_sdkman_candidate_local_versions "${COMP_WORDS[COMP_CWORD - 1]}"
mapfile -t COMPREPLY < <(compgen -W "$CANDIDATE_VERSIONS" -- "${COMP_WORDS[COMP_CWORD]}")
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "$CANDIDATE_VERSIONS" -- "${COMP_WORDS[COMP_CWORD]}")
;;
"install" | "i")
_sdkman_candidate_all_versions "${COMP_WORDS[COMP_CWORD - 1]}"
mapfile -t COMPREPLY < <(compgen -W "$CANDIDATE_VERSIONS" -- "${COMP_WORDS[COMP_CWORD]}")
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "$CANDIDATE_VERSIONS" -- "${COMP_WORDS[COMP_CWORD]}")
;;
*) ;;

Expand Down
27 changes: 14 additions & 13 deletions completion/available/sqlmap.completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
_command_exists sqlmap || return

function _sqlmap() {
local cur prev
local cur prev line

COMPREPLY=()
cur="$(_get_cword)"
Expand All @@ -20,7 +20,7 @@ function _sqlmap() {

# List directory content
--tamper)
IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W "${tamper:-}" -- "$cur")"
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${tamper:-}" -- "$cur")
return 0
;;
--output-dir | -t | -l | -m | -r | --load-cookies | --proxy-file | --sql-file | --shared-lib | --file-write)
Expand All @@ -32,43 +32,43 @@ function _sqlmap() {
return 0
;;
--method)
IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W 'GET POST PUT' -- "$cur")"
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W 'GET POST PUT' -- "$cur")
return 0
;;
--auth-type)
IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W 'Basic Digest NTLM PKI' -- "$cur")"
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W 'Basic Digest NTLM PKI' -- "$cur")
return 0
;;
--tor-type)
IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W 'HTTP SOCKS4 SOCKS5' -- "$cur")"
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W 'HTTP SOCKS4 SOCKS5' -- "$cur")
return 0
;;
-v)
IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W '1 2 3 4 5 6' -- "$cur")"
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W '1 2 3 4 5 6' -- "$cur")
return 0
;;
--dbms)
IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W 'mysql mssql access postgres' -- "$cur")"
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W 'mysql mssql access postgres' -- "$cur")
return 0
;;
--level | --crawl)
IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W '1 2 3 4 5' -- "$cur")"
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W '1 2 3 4 5' -- "$cur")
return 0
;;
--risk)
IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W '0 1 2 3' -- "$cur")"
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W '0 1 2 3' -- "$cur")
return 0
;;
--technique)
IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W 'B E U S T Q' -- "$cur")"
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W 'B E U S T Q' -- "$cur")
return 0
;;
-s)
_filedir sqlite
return 0
;;
--dump-format)
IFS=' ' read -r -a COMPREPLY <<< "$(compgen -W 'CSV HTML SQLITE' -- "$cur")"
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W 'CSV HTML SQLITE' -- "$cur")
return 0
;;
-x)
Expand All @@ -78,7 +78,8 @@ function _sqlmap() {
esac

if [[ "$cur" == * ]]; then
IFS=' ' read -r -a COMPREPLY <<< "$(
COMPREPLY=()
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(
compgen -W '-h --help -hh --version -v -d -u --url -l -x -m -r -g -c --method \
--data --param-del --cookie --cookie-del --load-cookies \
--drop-set-cookie --user-agent --random-agent --host --referer \
Expand Down Expand Up @@ -109,7 +110,7 @@ function _sqlmap() {
--dependencies --disable-coloring --gpage --identify-waf \
--mobile --page-rank --purge-output --smart \
--sqlmap-shell --wizard' -- "$cur"
)"
)
# this removes any options from the list of completions that have
# already been specified somewhere on the command line, as long as
# these options can only be used once (in a word, "options", in
Expand Down
3 changes: 2 additions & 1 deletion lint_clean_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# - Comment lines (#) are ignored
#
# shellcheck disable=SC2002 # Prefer 'cat' for cleaner script
mapfile -t FILES < <(
FILES=()
while IFS='' read -r line; do FILES+=("$line"); done < <(
cat clean_files.txt \
| grep -E -v '^\s*$' \
| grep -E -v '^\s*#' \
Expand Down
1 change: 1 addition & 0 deletions plugins/available/fasd.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'load fasd, if you are using it'

Expand Down
15 changes: 9 additions & 6 deletions plugins/available/fzf.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# shellcheck shell=bash
# Load after the system completion to make sure that the fzf completions are working
# BASH_IT_LOAD_PRIORITY: 375

cite about-plugin
about-plugin 'load fzf, if you are using it'

if [ -r ~/.fzf.bash ]; then
# shellcheck disable=SC1090
source ~/.fzf.bash
elif [ -r "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash ]; then
# shellcheck disable=SC1091
source "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash
fi

Expand All @@ -23,10 +26,10 @@ fe() {
param "1: Search term"
example "fe foo"

local IFS=$'\n'
local files
files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
[[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}"
local IFS=$'\n' line
local files=()
while IFS='' read -r line; do files+=("$line"); done < <(fzf-tmux --query="$1" --multi --select-1 --exit-0)
[[ -n "${files[0]}" ]] && ${EDITOR:-vim} "${files[@]}"
}

fcd() {
Expand All @@ -36,7 +39,7 @@ fcd() {
example "fcd aliases"

local dir
dir=$(find ${1:-.} -path '*/\.*' -prune \
dir=$(find "${1:-.}" -path '*/\.*' -prune \
-o -type d -print 2> /dev/null | fzf +m) \
&& cd "$dir"
&& cd "$dir" || return 1
}
2 changes: 2 additions & 0 deletions plugins/available/gitstatus.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'speeds up your life by using gitstatus for git status calculations. install from https://github.com/romkatv/gitstatus'

Expand All @@ -17,6 +18,7 @@ function gitstatus_on_disable() {

: "${SCM_GIT_GITSTATUS_DIR:="$HOME/gitstatus"}"
if [[ -d ${SCM_GIT_GITSTATUS_DIR} ]]; then
# shellcheck disable=SC1091
source "${SCM_GIT_GITSTATUS_DIR}/gitstatus.plugin.sh"
# Start the actual gitstatus binary
gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1
Expand Down
1 change: 1 addition & 0 deletions plugins/available/hg.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'hg helper functions'

Expand Down
1 change: 1 addition & 0 deletions plugins/available/javascript.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# shellcheck shell=bash
# The install directory is hard-coded. TODO: allow the directory to be specified on the command line.

cite about-plugin
Expand Down
1 change: 1 addition & 0 deletions plugins/available/jenv.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'load jenv, if you are using it'

Expand Down
6 changes: 3 additions & 3 deletions plugins/available/osx-timemachine.plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function time-machine-list-machines() {
group "osx-timemachine"
about "Lists the OS X Time Machine machines on the backup volume"

local tmdest
local tmdest line
tmdest="$(time-machine-destination)/Backups.backupdb"

find "$tmdest" -maxdepth 1 -mindepth 1 -type d | grep -v "/\." | while read -r line; do
Expand All @@ -32,7 +32,7 @@ function time-machine-list-all-backups() {
example "time-machine-list-all-backups my-laptop"

# Use the local hostname if none provided
local COMPUTERNAME BACKUP_LOCATION
local COMPUTERNAME BACKUP_LOCATION line
COMPUTERNAME=${1:-$(scutil --get ComputerName)}
BACKUP_LOCATION="$(time-machine-destination)/Backups.backupdb/$COMPUTERNAME"

Expand All @@ -48,7 +48,7 @@ function time-machine-list-old-backups() {
example "time-machine-list-old-backups my-laptop"

# Use the local hostname if none provided
local COMPUTERNAME BACKUP_LOCATION
local COMPUTERNAME BACKUP_LOCATION line
COMPUTERNAME=${1:-$(scutil --get ComputerName)}
BACKUP_LOCATION="$(time-machine-destination)/Backups.backupdb/$COMPUTERNAME"

Expand Down
20 changes: 12 additions & 8 deletions plugins/available/pack.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# shellcheck shell=bash
# bash completion for pack -*- shell-script -*-

cite about-plugin
Expand Down Expand Up @@ -43,13 +44,14 @@ __pack_handle_reply() {
if [[ $(type -t compopt) = "builtin" ]]; then
compopt -o nospace
fi
local allflags
local allflags line
if [ ${#must_have_one_flag[@]} -ne 0 ]; then
allflags=("${must_have_one_flag[@]}")
else
allflags=("${flags[*]} ${two_word_flags[*]}")
fi
COMPREPLY=($(compgen -W "${allflags[*]}" -- "$cur"))
COMPREPLY=()
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${allflags[*]}" -- "$cur")
if [[ $(type -t compopt) = "builtin" ]]; then
[[ "${COMPREPLY[0]}" == *= ]] || compopt +o nospace
fi
Expand All @@ -65,7 +67,7 @@ __pack_handle_reply() {
__pack_index_of_word "${flag}" "${flags_with_completion[@]}"
COMPREPLY=()
if [[ ${index} -ge 0 ]]; then
PREFIX=""
# PREFIX=""
cur="${cur#*=}"
${flags_completion[${index}]}
if [ -n "${ZSH_VERSION}" ]; then
Expand All @@ -79,7 +81,7 @@ __pack_handle_reply() {
esac

# check if we are handling a flag with special work handling
local index
local index completions line
__pack_index_of_word "${prev}" "${flags_with_completion[@]}"
if [[ ${index} -ge 0 ]]; then
${flags_completion[${index}]}
Expand All @@ -91,18 +93,19 @@ __pack_handle_reply() {
return
fi

local completions
completions=("${commands[@]}")
if [[ ${#must_have_one_noun[@]} -ne 0 ]]; then
completions=("${must_have_one_noun[@]}")
fi
if [[ ${#must_have_one_flag[@]} -ne 0 ]]; then
completions+=("${must_have_one_flag[@]}")
fi
COMPREPLY=($(compgen -W "${completions[*]}" -- "$cur"))
COMPREPLY=()
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${completions[*]}" -- "$cur")

if [[ ${#COMPREPLY[@]} -eq 0 && ${#noun_aliases[@]} -gt 0 && ${#must_have_one_noun[@]} -ne 0 ]]; then
COMPREPLY=($(compgen -W "${noun_aliases[*]}" -- "$cur"))
COMPREPLY=()
while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${noun_aliases[*]}" -- "$cur")
fi

if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
Expand All @@ -129,7 +132,7 @@ __pack_handle_filename_extension_flag() {

__pack_handle_subdirs_in_dir_flag() {
local dir="$1"
pushd "${dir}" > /dev/null 2>&1 && _filedir -d && popd > /dev/null 2>&1
pushd "${dir}" > /dev/null 2>&1 && _filedir -d && popd > /dev/null 2>&1 || return 1
}

__pack_handle_flag() {
Expand Down Expand Up @@ -567,6 +570,7 @@ _pack_root_command() {

__start_pack() {
local cur prev words cword
#shellcheck disable=SC2034
declare -A flaghash 2> /dev/null || :
declare -A aliashash 2> /dev/null || :
if declare -F _init_completion > /dev/null 2>&1; then
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/dsifford/yarn-completion/yarn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c4baa6e

Please sign in to comment.