Skip to content

Commit e691826

Browse files
authored
Fix all ShellCheck errors and add to CI (tj#1179)
1 parent fdaca2c commit e691826

File tree

7 files changed

+22
-15
lines changed

7 files changed

+22
-15
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636
env:
3737
# NOTE: use env to pass the output in order to avoid possible injection attacks
3838
FILES: "${{ steps.files.outputs.added_modified }}"
39+
- name: Shellcheck
40+
run: shellcheck --severity=error bin/* ./*.sh
3941
- name: Lint and format Python with Ruff
4042
uses: astral-sh/ruff-action@v2
4143

bin/git-create-branch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ then
3939
REMOTE=origin
4040
fi
4141

42-
test -z $BRANCH && echo "branch argument required." 1>&2 && exit 1
42+
test -z "$BRANCH" && echo "branch argument required." 1>&2 && exit 1
4343

4444
if [[ -n $REMOTE ]]
4545
then

bin/git-fork

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ else
6161
# clone forked repo into current dir
6262
git clone "${remote_prefix}${user}/${project}.git" "$project"
6363
# add reference to origin fork so can merge in upstream changes
64-
cd "$project"
64+
cd "$project" || exit
6565
git remote add upstream "${remote_prefix}${owner}/${project}.git"
6666
git fetch upstream
6767
fi

bin/git-guilt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ do
3131
esac
3232
done
3333

34-
cd "$(git-root)" # cd for git blame
34+
cd "$(git-root)" || exit # cd for git blame
3535
MERGED_LOG=$(git_extra_mktemp)
3636
if [[ $EMAIL == '-e' ]]
3737
then
@@ -44,9 +44,11 @@ for file in $(git diff --name-only "$@")
4444
do
4545
test -n "$DEBUG" && echo "git blame $file"
4646
# $1 - since $2 - until
47+
# shellcheck disable=SC2086
4748
git blame $NOT_WHITESPACE --line-porcelain "$1" -- "$file" 2> /dev/null |
4849
LC_ALL=C sed -n "$PATTERN" | sort | uniq -c | LC_ALL=C sed 's/^\(.\)/- \1/' >> "$MERGED_LOG"
4950
# if $2 not given, use current commit as "until"
51+
# shellcheck disable=SC2086
5052
git blame $NOT_WHITESPACE --line-porcelain "${2-@}" -- "$file" 2> /dev/null |
5153
LC_ALL=C sed -n "$PATTERN" | sort | uniq -c | LC_ALL=C sed 's/^\(.\)/+ \1/' >> "$MERGED_LOG"
5254
done
@@ -71,7 +73,7 @@ END {
7173
printf("%d %s\n", contributors[people], people)
7274
}
7375
}
74-
}' $MERGED_LOG | sort -nr | # only gawk supports built-in sort function
76+
}' "$MERGED_LOG" | sort -nr | # only gawk supports built-in sort function
7577
while read -r line
7678
do
7779
people=${line#* }
@@ -103,7 +105,7 @@ do
103105
do
104106
printf "-"
105107
done
106-
printf "(%s)" $num
108+
printf "(%s)" "$num"
107109
else
108110
for (( i = 0; i > num; i-- ))
109111
do

bin/git-obliterate

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ do
99
file="$file"' '"$i"
1010
shift
1111
done
12-
test -n "$*" && range="$*"
12+
test -n "$*" && range=("$@")
1313

1414
test -z "$file" && echo "file required." 1>&2 && exit 1
15-
if [ -z "$range" ]
15+
if [ -z "${range[*]}" ]
1616
then
1717
git filter-branch -f --index-filter "git rm -r --cached ""$file"" --ignore-unmatch" \
1818
--prune-empty --tag-name-filter cat -- --all
1919
else
20-
# don't quote $range so that we can forward multiple rev-list arguments
20+
# $range is an array so that we can forward multiple rev-list arguments
2121
git filter-branch -f --index-filter "git rm -r --cached ""$file"" --ignore-unmatch" \
22-
--prune-empty --tag-name-filter cat -- $range
22+
--prune-empty --tag-name-filter cat -- "${range[@]}"
2323
fi

bin/git-repl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ while true; do
4444
esac
4545

4646
if [[ $cmd == !* ]]; then
47+
# shellcheck disable=SC2086
4748
eval ${cmd:1}
4849
elif [[ $cmd == git* ]]; then
50+
# shellcheck disable=SC2086
4951
eval $cmd
5052
else
5153
eval git "$cmd"

bin/git-scp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function php_lint()
5959

6060
function _dos2unix()
6161
{
62-
command -v dos2unix > /dev/null && dos2unix $@
62+
command -v dos2unix > /dev/null && dos2unix "$@"
6363
return 0
6464
}
6565

@@ -68,8 +68,8 @@ function _sanitize()
6868
git config --get-all extras.scp.sanitize | while read -r i
6969
do
7070
case $i in
71-
php_lint) php_lint $@;; # git config --global --add extras.scp.sanitize php_lint
72-
dos2unix) _dos2unix $@;; # git config --global --add extras.scp.sanitize dos2unix
71+
php_lint) php_lint "$@";; # git config --global --add extras.scp.sanitize php_lint
72+
dos2unix) _dos2unix "$@";; # git config --global --add extras.scp.sanitize dos2unix
7373
esac
7474
done
7575
return $?
@@ -107,6 +107,7 @@ function scp_and_stage
107107
if [ -n "$list" ]
108108
then
109109
local _TMP=${0///}
110+
# shellcheck disable=SC2086
110111
echo "$list" > "$_TMP" &&
111112
_sanitize $list &&
112113
_info "Pushing to $remote ($(git config "remote.$remote.url"))" &&
@@ -131,7 +132,7 @@ function reverse_scp()
131132
shift
132133

133134
local _TMP=${0///}
134-
echo $@ > "$_TMP" &&
135+
echo "$@" > "$_TMP" &&
135136
rsync -rlDv --files-from="$_TMP" "$(git config "remote.$remote.url")/" ./ &&
136137
rm "$_TMP"
137138
}
@@ -173,8 +174,8 @@ case $(basename "$0") in
173174
git-scp)
174175
case $1 in
175176
''|-h|'?'|help|--help) shift; _test_git_scp; _usage "$@";;
176-
*) scp_and_stage $@;;
177+
*) scp_and_stage "$@";;
177178
esac
178179
;;
179-
git-rscp) reverse_scp $@;;
180+
git-rscp) reverse_scp "$@";;
180181
esac

0 commit comments

Comments
 (0)