Skip to content

Commit b81d293

Browse files
committed
🐚 Rebuild documentation if Vim files change
1 parent 790b955 commit b81d293

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

hooks/pre-commit

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,40 @@ else
2323
printf >&2 ' %s\n' "${_files_to_be_commited[@]}"
2424
fi
2525

26-
_args=(
26+
_test_args=(
2727
--test 'units'
2828
--cicd
2929
)
3030

3131
if [[ -x "${__G_DIR__}/scripts/vader-run-tests.sh" ]]; then
32-
_exec_path="${__G_DIR__}/scripts/vader-run-tests.sh"
32+
_test_exec_path="${__G_DIR__}/scripts/vader-run-tests.sh"
33+
_vimdoc_target="${__G_DIR__}"
3334
elif [[ -x "${__GG_DIR__}/scripts/vader-run-tests.sh" ]]; then
34-
_exec_path="${__GG_DIR__}/scripts/vader-run-tests.sh"
35+
_test_exec_path="${__GG_DIR__}/scripts/vader-run-tests.sh"
36+
_vimdoc_target="${__GG_DIR__}"
3537
else
3638
printf >&2 'Cannot find executable path for -> scripts/vader-run-tests.sh\n'
3739
exit 127
3840
fi
3941

42+
_vimdoc_exec_path="$(which vimdoc)"
43+
if grep -qE -- '\.vim\>' <<<"${_files_to_be_commited[*]}"; then
44+
if [[ -x "${_vimdoc_exec_path}" ]]; then
45+
printf >&2 '%s: Running vimdoc because you are committing:\n' "${__NAME__}"
46+
printf >&2 ' %s\n' "${_files_to_be_commited[@]}"
47+
"${_vimdoc_exec_path}" "${_vimdoc_target}"
48+
else
49+
printf >&2 '%s: Warning no vimdoc executable found but changes detected for vim files\n' "${__NAME__}"
50+
fi
51+
fi
52+
53+
54+
55+
4056
##
4157
# Warning: doing `command 2>&1 | parser` causes spaces to be injected outside
4258
# of what `parser` can capture?!
43-
"${_exec_path}" "${_args[@]}" 2> >(
59+
"${_test_exec_path}" "${_test_args[@]}" 2> >(
4460
awk 'BEGIN {
4561
delete _buffered_lines;
4662
_current_vader_file = "";

0 commit comments

Comments
 (0)