forked from labbots/google-drive-upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
format.sh
executable file
·35 lines (30 loc) · 974 Bytes
/
format.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env sh
if ! command -v shfmt 2>| /dev/null 1>&2; then
printf 'Install shfmt to format script\n\n'
printf 'Check https://github.com/mvdan/sh/releases\n'
exit 1
fi
CURRENT_DIR="$(pwd)"
TEMPFILE="${CURRENT_DIR}/$(date +%s)"
trap 'rm -f "${TEMPFILE}".failedlog "${TEMPFILE}".passedlog' INT TERM EXIT
for k in . sh bash; do
cd "${k}" 2>| /dev/null 1>&2 || exit 1
for i in *.*sh; do
if ! shfmt -w "${i}"; then
printf "%s\n\n" "${k}/${i}: ERROR" >> "${TEMPFILE}".failedlog
else
printf "%s\n" "${k}/${i}: SUCCESS" >> "${TEMPFILE}".passedlog
fi
done
cd - 2>| /dev/null 1>&2 || exit 1
done
if [ -f "${TEMPFILE}.failedlog" ]; then
printf '\nError: Cannot format some files.\n\n'
grep '.*' "${TEMPFILE}".failedlog && printf "\n"
grep '.*' "${TEMPFILE}".passedlog
exit 1
else
printf 'All files formatted successfully.\n\n'
grep '.*' "${TEMPFILE}".passedlog
exit 0
fi