File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash -e
2+
3+ #
4+ # Interactively lint & format shell scripts in the build-scripts directory.
5+ #
6+ # Dependencies:
7+ # * shfmt
8+ # * shellcheck
9+ #
10+ # This script takes no arguments can be executed from anywhere, e.g.:
11+ # $ ./user-scripts/check-scripts.sh
12+ #
13+
14+ BUILD_SCRIPTS=" $( dirname " $0 " ) " /../build-scripts
15+
16+ grep -Erl ' ^(#!/(bin|usr/bin)/(env )?(sh|bash))' " $BUILD_SCRIPTS " | sort | while read -r filepath; do
17+ filename=$( basename " $filepath " )
18+
19+ if ! shfmt --diff --indent=4 " $filepath " ; then
20+ echo
21+ echo " File '$filename ' requires formatting."
22+ read -r -p " Do you wish to format '$filename '? [y/N] " answer < /dev/tty
23+ case $answer in
24+ [yY] | [yY][eE][sS])
25+ echo " Formatting file '$filename '..."
26+ shfmt --write --indent=4 " $filepath "
27+ ;;
28+ * )
29+ echo " Skipping formatting of file '$filename '..."
30+ ;;
31+ esac
32+ fi
33+
34+ if ! shellcheck --external-sources --source-path=" $BUILD_SCRIPTS " " $filepath " ; then
35+ echo
36+ echo " File '$filename ' requires manual intervention."
37+ read -n 1 -s -r -p " Press any key to continue..." < /dev/tty
38+ echo
39+ fi
40+ done
You can’t perform that action at this time.
0 commit comments