Placate shellcheck

This commit is contained in:
Oliver Blanthorn 2019-05-29 21:09:58 +01:00
parent 6a0338d132
commit 68aff53e4d
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
3 changed files with 19 additions and 14 deletions

View file

@ -32,7 +32,8 @@ prettierUgly() {
tslintUgly() { tslintUgly() {
local acc="" local acc=""
local IFS=$'\n' local IFS=$'\n'
local tmpdir=$(mktemp -d "tslint.XXXXXXXXX") local tmpdir
tmpdir=$(mktemp -d "tslint.XXXXXXXXX")
for jsfile in "$@"; do for jsfile in "$@"; do
tmpfile="$tmpdir/$jsfile" tmpfile="$tmpdir/$jsfile"
mkdir -p "$(dirname "$tmpfile")" mkdir -p "$(dirname "$tmpfile")"
@ -50,5 +51,5 @@ noisy() {
acc+=("jsfile") acc+=("jsfile")
fi fi
done done
echo ${acc[@]} echo "${acc[@]}"
} }

View file

@ -24,14 +24,16 @@ unlock() {
rm "$1" rm "$1"
} }
trap "unlock $(git rev-parse --show-toplevel)/.git/index.lock || true" ERR trap 'unlock $(git rev-parse --show-toplevel)/.git/index.lock || true' ERR
main() { main() {
local stagedFiles="$(cachedTSLintFiles)"$'\n'"$(cachedPrettierFiles)" local stagedFiles
stagedFiles="$(cachedTSLintFiles)"$'\n'"$(cachedPrettierFiles)"
if [ -n "$stagedFiles" ]; then if [ -n "$stagedFiles" ]; then
# Could use git-update-index --cacheinfo to add a file without creating directories and stuff. # Could use git-update-index --cacheinfo to add a file without creating directories and stuff.
local tmpdir=$(mktemp -d "pretty.XXXXXXXXX") local tmpdir
tmpdir=$(mktemp -d "pretty.XXXXXXXXX")
IFS=$'\n' IFS=$'\n'
for file in $stagedFiles; do for file in $stagedFiles; do
if cmp -s <(staged "$file") "$file"; then if cmp -s <(staged "$file") "$file"; then
@ -47,12 +49,14 @@ main() {
echo "WARN: Staged copy of '$file' does not match working copy: only prettifying staged copy." echo "WARN: Staged copy of '$file' does not match working copy: only prettifying staged copy."
( (
cd "$tmpdir" cd "$tmpdir"
mkdir -p $(dirname $file) mkdir -p "$(dirname "$file")"
lock ../.git/index.lock lock ../.git/index.lock
tmpfile=$(mktemp "pretty.XXXXXXXXX")
case "$file" in case "$file" in
*.md | *.css) staged "$file" | prettier --stdin-filepath "$file" > "$file";; *.md | *.css) staged "$file" | prettier --stdin-filepath "$file" > "$tmpfile" && mv "$tmpfile" "$file";;
*) staged "$file" > "$file" *) staged "$file" > "$tmpfile"
tslint -c ../tslint.json --fix "$file" 2>/dev/null;; tslint -c ../tslint.json --fix "$tmpfile" 2>/dev/null
mv "$tmpfile" "$file";;
esac esac
chmod --reference="../$file" "$file" # match permissions chmod --reference="../$file" "$file" # match permissions
# Can't hold lock while git add occurs. Hopefully release and reacquire happen fast enough to prevent race. # Can't hold lock while git add occurs. Hopefully release and reacquire happen fast enough to prevent race.

View file

@ -30,14 +30,14 @@ checkRequiredVersions() {
colorEcho \ colorEcho \
'[-] p7zip minimum version '"${MIN_7ZIP_VER}"' required\n' \ '[-] p7zip minimum version '"${MIN_7ZIP_VER}"' required\n' \
"alert" "alert"
exit -1 exit 1
fi fi
if ! wine --version 2> /dev/null | grep -q "wine-${MIN_WINE_VER}"; then if ! wine --version 2> /dev/null | grep -q "wine-${MIN_WINE_VER}"; then
colorecho \ colorecho \
'[-] wine minimum version '"${MIN_WINE_VER}"' required\n' \ '[-] wine minimum version '"${MIN_WINE_VER}"' required\n' \
"alert" "alert"
exit -1 exit 1
fi fi
} }
@ -59,7 +59,7 @@ colorEcho() {
local str="$1" local str="$1"
local color="${COLOR_GOOD}${COLOR_BOLD}" local color="${COLOR_GOOD}${COLOR_BOLD}"
if [ ! -z "$2" ] \ if [ -n "$2" ] \
&& [ "$(stripWhitespace "$2")" = "alert" ]; then && [ "$(stripWhitespace "$2")" = "alert" ]; then
color="${COLOR_BAD}${COLOR_BOLD}" color="${COLOR_BAD}${COLOR_BOLD}"
fi fi
@ -74,7 +74,7 @@ checkPrerequisite() {
printf '%s\n' " - '${bin_name}' found." printf '%s\n' " - '${bin_name}' found."
else else
printf '%s\n' " - '$1' not found, quitting ..." printf '%s\n' " - '$1' not found, quitting ..."
exit -1 exit 1
fi fi
} }
@ -160,7 +160,7 @@ mainFunction() {
colorEcho \ colorEcho \
'[-] PyInstaller compilation failed, quitting ...\n' \ '[-] PyInstaller compilation failed, quitting ...\n' \
"alert" "alert"
exit -1 exit 1
fi fi
} }