Skip to content

Commit 8c9013e

Browse files
author
Adrián González Rus
committed
Add watch script
1 parent 48c0d71 commit 8c9013e

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

run

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22

33
# Defined scripts.
44
function lint() {
5+
_check_binaries "shellcheck"
56
shellcheck --format=tty --shell=sh ./**/*.sh
67
}
78

89
function test() {
9-
find . -name "*.bats" -exec sh -c "bats {}" ";"
10+
_check_binaries "bats"
11+
find . -iname "*.bats" -exec sh -c "bats {}" ";"
1012
}
1113

1214
function format() {
13-
find . -name "*.sh" -exec sh -c "shfmt -bn -ci -w {}" ";"
15+
_check_binaries "shfmt"
16+
find . -iname "*.sh" -exec sh -c "shfmt -bn -ci -w {}" ";"
17+
}
18+
19+
function watch() {
20+
_check_binaries "entr"
21+
find . -type f -iname "*.sh" -o -iname "*.bats" | entr -c bash run check
1422
}
1523

1624
function check() {
@@ -22,13 +30,13 @@ function check() {
2230
set -e
2331

2432
# Check binaries.
25-
[ -x "$(command -v shellcheck)" ] || {
26-
echo "shellcheck is required" >&2
27-
exit 1
28-
}
29-
[ -x "$(command -v bats)" ] || {
30-
echo "bats is required" >&2
31-
exit 1
33+
function _check_binaries() {
34+
for i in "$@"; do
35+
[ -x "$(command -v "$i")" ] || {
36+
echo "bats is required" >&2
37+
exit 1
38+
}
39+
done
3240
}
3341

3442
# Check for scripts.

0 commit comments

Comments
 (0)