Delete .shellcheckrc (#1947)

* CI: disable Ubuntu 16.04 as it's EOL

https://github.blog/changelog/2021-04-29-github-actions-ubuntu-16-04-lts-virtual-environment-will-be-removed-on-september-20-2021/

* main: lint false positive

* install: lint

* plugins/cmd-returned-notify: don't `export`

* plugins/xterm: lint

* plugins/git: lint

* plugins/goenv: lint

* plugins/alias-completion: lint false positives

* plugins/alias-completion: fix SC2155, SC2154

Declare `locals` at the top of the function

* completion: lint completions using `bash_completion` functions

Match the style of the existing code

* completion/knife: lint false positives

* completion/knife: lint

* completion/sdkman: lint

* completion/composer: lint

* Move `.shellcheckrc` under `themes/`

* lib/theme: fix SC2155, SC2154, SC2034

* lib/colors: don't warn on unused variables

We assign a large number of variables here and they may or may not be used anywhere else, so disable SC2034 for this file (only).

Alsö disable SC2005 as the functions in this file were written before `printf` was invented and have to do some fancy metascripting to get escape sequences interpreted reliably. I’m not smart enough to fix this to use `printf`, so leave it for now.

* themes/agnoster: lint

* themes: disable SC2154 for colors

Each one of these themes will need it’s own fix for SC2154, possibly upstream.

Due to the way themes are, it's entirely normal to have a *lot* of false positives for SC2034. So much so, that I have to admit that it is probably just not worth linting for SC2034 despite my dislike of blanket ignore rules.

* themes: disable SC2154, fix SC2155

Each one of these themes will need it’s own fix for SC2154, possibly upstream.

Due to the way themes are, it's entirely normal to have a *lot* of false positives for SC2034. So much so, that I have to admit that it is probably just not worth linting for SC2034 despite my dislike of blanket ignore rules.

* Delete `.shellcheckrc`

* remove executable bit
This commit is contained in:
John D Pell
2021-09-18 02:50:59 -07:00
committed by GitHub
parent b48f3fd7d3
commit 1c3cbf7ca6
44 changed files with 183 additions and 126 deletions

View File

@@ -19,6 +19,8 @@ about-plugin 'Automatic completion of aliases'
# Automatically add completion for all aliases to commands having completion functions
function alias_completion {
local namespace="alias_completion"
local tmp_file completion_loader alias_name alias_tokens line completions
local alias_arg_words new_completion compl_func compl_wrapper
# parse function based completion definitions, where capture group 2 => function and 3 => trigger
local compl_regex='complete( +[^ ]+)* -F ([^ ]+) ("[^"]+"|[^ ]+)'
@@ -26,28 +28,25 @@ function alias_completion {
local alias_regex="alias( -- | )([^=]+)='(\"[^\"]+\"|[^ ]+)(( +[^ ]+)*)'"
# create array of function completion triggers, keeping multi-word triggers together
eval "local completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))"
eval "completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))"
((${#completions[@]} == 0)) && return 0
# create temporary file for wrapper functions and completions
local tmp_file
tmp_file="$(mktemp -t "${namespace}-${RANDOM}XXXXXX")" || return 1
local completion_loader
completion_loader="$(complete -p -D 2> /dev/null | sed -Ene 's/.* -F ([^ ]*).*/\1/p')"
# read in "<alias> '<aliased command>' '<command args>'" lines from defined aliases
local line
# shellcheck disable=SC2162
# some aliases do have backslashes that needs to be interpreted
# shellcheck disable=SC2162
while read line; do
eval "local alias_tokens; alias_tokens=($line)" 2> /dev/null || continue # some alias arg patterns cause an eval parse error
local alias_name="${alias_tokens[0]}" alias_cmd="${alias_tokens[1]}" alias_args="${alias_tokens[2]# }"
eval "alias_tokens=($line)" 2> /dev/null || continue # some alias arg patterns cause an eval parse error
# shellcheck disable=SC2154 # see `eval` above
alias_name="${alias_tokens[0]}" alias_cmd="${alias_tokens[1]}" alias_args="${alias_tokens[2]# }"
# skip aliases to pipes, boolean control structures and other command lists
# (leveraging that eval errs out if $alias_args contains unquoted shell metacharacters)
eval "local alias_arg_words; alias_arg_words=($alias_args)" 2> /dev/null || continue
eval "alias_arg_words=($alias_args)" 2> /dev/null || continue
# avoid expanding wildcards
read -a alias_arg_words <<< "$alias_args"
@@ -63,15 +62,15 @@ function alias_completion {
continue
fi
fi
local new_completion="$(complete -p "$alias_cmd" 2> /dev/null)"
new_completion="$(complete -p "$alias_cmd" 2> /dev/null)"
# create a wrapper inserting the alias arguments if any
if [[ -n $alias_args ]]; then
local compl_func="${new_completion/#* -F /}"
compl_func="${new_completion/#* -F /}"
compl_func="${compl_func%% *}"
# avoid recursive call loops by ignoring our own functions
if [[ "${compl_func#_"$namespace"::}" == "$compl_func" ]]; then
local compl_wrapper="_${namespace}::${alias_name}"
compl_wrapper="_${namespace}::${alias_name}"
echo "function $compl_wrapper {
local compl_word=\$2
local prec_word=\$3

View File

@@ -9,7 +9,7 @@ precmd_return_notification() {
}
preexec_return_notification() {
[ -z "${LAST_COMMAND_TIME}" ] && export LAST_COMMAND_TIME=$(date +%s)
[[ -z "${LAST_COMMAND_TIME}" ]] && LAST_COMMAND_TIME=$(date +%s)
}
precmd_functions+=(precmd_return_notification)

View File

@@ -2,12 +2,13 @@
cite about-plugin
about-plugin 'git helper functions'
# shellcheck disable=SC2016
function git_remote {
about "adds remote $GIT_HOSTING:$1 to current repo"
about 'adds remote $GIT_HOSTING:$1 to current repo'
group "git"
echo "Running: git remote add origin ${GIT_HOSTING}:$1.git"
git remote add origin "$GIT_HOSTING:$1".git
echo "Running: git remote add origin ${GIT_HOSTING:?}:$1.git"
git remote add origin "${GIT_HOSTING}:${1}".git
}
function git_first_push {
@@ -24,14 +25,14 @@ function git_pub() {
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Publishing ${BRANCH} to remote origin"
git push -u origin "$BRANCH"
git push -u origin "${BRANCH}"
}
function git_revert() {
about 'applies changes to HEAD that revert all changes after this commit'
group 'git'
git reset "$1"
git reset "${1:?}"
git reset --soft "HEAD@{1}"
git commit -m "Revert to ${1}"
git reset --hard
@@ -49,9 +50,7 @@ function git_rollback() {
}
function commit_exists() {
git rev-list --quiet "$1"
status=$?
if [ $status -ne 0 ]; then
if git rev-list --quiet "${1:?}"; then
echo "Commit ${1} does not exist"
kill -INT $$
fi
@@ -61,7 +60,7 @@ function git_rollback() {
while true; do
# shellcheck disable=SC2162
read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP
case $RESP in
case "${RESP}" in
[yY])
echo "Rolling back to commit ${1} with unstaged changes"
@@ -87,7 +86,7 @@ function git_rollback() {
while true; do
# shellcheck disable=SC2162
read -p "WARNING: This will change your history and move the current HEAD back to commit ${1}, continue? [Y/N]" RESP
case $RESP in
case "${RESP}" in
[yY])
keep_changes "$1"
@@ -134,8 +133,8 @@ function git_info() {
# print all remotes and thier details
for remote in $(git remote show); do
echo "$remote":
git remote show "$remote"
echo "${remote}":
git remote show "${remote}"
echo
done
@@ -172,32 +171,32 @@ function git_stats {
AUTHORS=$(git shortlog -sn --all | cut -f2 | cut -f1 -d' ')
LOGOPTS=""
if [ "$1" == '-w' ]; then
LOGOPTS="$LOGOPTS -w"
LOGOPTS="${LOGOPTS} -w"
shift
fi
if [ "$1" == '-M' ]; then
LOGOPTS="$LOGOPTS -M"
LOGOPTS="${LOGOPTS} -M"
shift
fi
if [ "$1" == '-C' ]; then
LOGOPTS="$LOGOPTS -C --find-copies-harder"
LOGOPTS="${LOGOPTS} -C --find-copies-harder"
shift
fi
for a in $AUTHORS; do
for a in ${AUTHORS}; do
echo '-------------------'
echo "Statistics for: $a"
echo "Statistics for: ${a}"
echo -n "Number of files changed: "
# shellcheck disable=SC2086
git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f3 | sort -iu | wc -l
git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f3 | sort -iu | wc -l
echo -n "Number of lines added: "
# shellcheck disable=SC2086
git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f1 | awk '{s+=$1} END {print s}'
git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f1 | awk '{s+=$1} END {print s}'
echo -n "Number of lines deleted: "
# shellcheck disable=SC2086
git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f2 | awk '{s+=$1} END {print s}'
git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f2 | awk '{s+=$1} END {print s}'
echo -n "Number of merges: "
# shellcheck disable=SC2086
git log $LOGOPTS --all --merges --author="$a" | grep -c '^commit'
git log ${LOGOPTS} --all --merges --author="${a}" | grep -c '^commit'
done
else
echo "you're currently not in a git repository"
@@ -212,18 +211,16 @@ function gittowork() {
result=$(curl -L "https://www.gitignore.io/api/$1" 2> /dev/null)
if [[ $result =~ ERROR ]]; then
if [[ "${result}" =~ ERROR ]]; then
echo "Query '$1' has no match. See a list of possible queries with 'gittowork list'"
elif [[ $1 = list ]]; then
echo "$result"
elif [[ $1 == list ]]; then
echo "${result}"
else
if [[ -f .gitignore ]]; then
result=$(echo "$result" | grep -v "# Created by http://www.gitignore.io")
result=$(grep -v "# Created by http://www.gitignore.io" <<< "${result}")
echo ".gitignore already exists, appending..."
echo "$result" >> .gitignore
else
echo "$result" > .gitignore
fi
echo "${result}" >> .gitignore
fi
}
@@ -257,7 +254,7 @@ function gitignore-reload() {
fi
# Prompt user to commit or stash changes and exit
if [ $err = 1 ]; then
if [[ "${err}" == 1 ]]; then
echo >&2 "Please commit or stash them."
fi
@@ -265,7 +262,7 @@ function gitignore-reload() {
# If we're here, then there are no uncommited or unstaged changes dangling around.
# Proceed to reload .gitignore
if [ $err = 0 ]; then
if [[ "${err}" == 0 ]]; then
# Remove all cached files
git rm -r --cached .
@@ -290,6 +287,7 @@ function git-changelog() {
return 1
fi
# shellcheck disable=SC2155
local NEXT=$(date +%F)
if [[ "$2" == "md" ]]; then
@@ -298,9 +296,9 @@ function git-changelog() {
# shellcheck disable=SC2162
git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do
echo
echo "### $DATE"
git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="$DATE 00:00:00" --until="$DATE 24:00:00"
NEXT=$DATE
echo "### ${DATE}"
git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="${DATE} 00:00:00" --until="${DATE} 24:00:00"
NEXT=${DATE}
done
else
echo "CHANGELOG $1"
@@ -309,9 +307,10 @@ function git-changelog() {
# shellcheck disable=SC2162
git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do
echo
echo "[$DATE]"
git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="$DATE 00:00:00" --until="$DATE 24:00:00"
NEXT=$DATE
echo "[${DATE}]"
git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="${DATE} 00:00:00" --until="${DATE} 24:00:00"
# shellcheck disable=SC2034
NEXT=${DATE}
done
fi
}

View File

@@ -30,7 +30,7 @@ eval "$(goenv init - bash)"
# If moving to a directory with a goenv version set, reload the shell
# to ensure the shell environment matches expectations.
_bash-it-goenv-preexec() {
export GOENV_OLD_VERSION="$(goenv version-name)"
GOENV_OLD_VERSION="$(goenv version-name)"
}
_bash-it-goenv-precmd() {
if [[ -n $GOENV_OLD_VERSION ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then

View File

@@ -3,29 +3,37 @@ cite about-plugin
about-plugin 'automatically set your xterm title with host and location info'
_short-dirname() {
local dir_name=$(dirs +0)
[ "$SHORT_TERM_LINE" = true ] && [ "${#dir_name}" -gt 8 ] && echo "${dir_name##*/}" || echo "${dir_name}"
local dir_name="${PWD/~/\~}"
if [[ "${SHORT_TERM_LINE:-}" == true && "${#dir_name}" -gt 8 ]]; then
echo "${dir_name##*/}"
else
echo "${dir_name}"
fi
}
_short-command() {
local input_command="$*"
[ "$SHORT_TERM_LINE" = true ] && [ "${#input_command}" -gt 8 ] && echo "${input_command%% *}" || echo "${input_command}"
if [[ "${SHORT_TERM_LINE:-}" == true && "${#input_command}" -gt 8 ]]; then
echo "${input_command%% *}"
else
echo "${input_command}"
fi
}
set_xterm_title() {
local title="$1"
echo -ne "\033]0;$title\007"
local title="${1:-}"
echo -ne "\033]0;${title}\007"
}
precmd_xterm_title() {
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) $PROMPT_CHAR"
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) ${PROMPT_CHAR:-\$}"
}
preexec_xterm_title() {
set_xterm_title "$(_short-command "${1}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
set_xterm_title "$(_short-command "${1:-}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
}
case "$TERM" in
case "${TERM:-dumb}" in
xterm* | rxvt*)
precmd_functions+=(precmd_xterm_title)
preexec_functions+=(preexec_xterm_title)