-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell-quality.sh
More file actions
executable file
·43 lines (38 loc) · 984 Bytes
/
Copy pathshell-quality.sh
File metadata and controls
executable file
·43 lines (38 loc) · 984 Bytes
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
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
# Run shellcheck/shfmt over tracked shell files without losing paths that
# contain spaces. harmon-devkit keeps intentionally incomplete snippets out of
# operational lint/format passes while still validating executable templates.
set -euo pipefail
mode="${1:-}"
[ "$#" -gt 0 ] && shift
exclude_snippets=false
if [ "${1:-}" = "--exclude-snippets" ]; then
exclude_snippets=true
shift
fi
files=()
if [ "$#" -gt 0 ]; then
files=("$@")
else
pathspecs=('*.sh' '*.bash')
if $exclude_snippets; then
pathspecs+=(':(exclude)snippets/**')
fi
while IFS= read -r -d '' file; do
files+=("$file")
done < <(git ls-files -z -- "${pathspecs[@]}")
fi
[ "${#files[@]}" -gt 0 ] || exit 0
case "$mode" in
check)
shellcheck --severity=error "${files[@]}"
shfmt -d "${files[@]}"
;;
format)
shfmt -w "${files[@]}"
;;
*)
echo "Usage: $0 <check|format> [--exclude-snippets] [file ...]" >&2
exit 2
;;
esac