aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Johnson <>2026-02-09 00:00:00 +0000
committerNicholas Johnson <>2026-02-10 00:00:00 +0000
commit218b12f48ccefd6649841beb7d1f97b168496f9bcaa92dc9f692dc53c72a0fdb (patch)
tree6b3e39377eb606770f0d11294b7af3946ace4be027fcbf701193aa87cdba62b6
parent5fa0c049a0e4482a0b5c35553dd9b3cebe07f8f45beb9213fb80a1e1d2b804b7 (diff)
downloadjournal-218b12f48ccefd6649841beb7d1f97b168496f9bcaa92dc9f692dc53c72a0fdb.tar.gz
journal-218b12f48ccefd6649841beb7d1f97b168496f9bcaa92dc9f692dc53c72a0fdb.zip
Add grammar checking script
A Markdown parser will eventually be added to prevent language_tool_python from grammar checking markup. Also the output will be reduced to just the errors and the script will not prompt for confirmation if no errors are detected. Currently, it always prompts.
-rwxr-xr-xhooks/pre-commit30
1 files changed, 30 insertions, 0 deletions
diff --git a/hooks/pre-commit b/hooks/pre-commit
new file mode 100755
index 0000000..317ed48
--- /dev/null
+++ b/hooks/pre-commit
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+# automatically configured by git-annex
+git annex pre-commit .
+
+# check grammar of staged Markdown files
+check_grammar() {
+ # get list of staged Markdown files (added or modified)
+ staged_files=$(git diff --cached --name-only --diff-filter=AM | grep '\.md$')
+
+ [ -z "$staged_files" ] && return 0
+
+ printf "Checking grammar of staged files.\n"
+ language_tool_python --picky $staged_files
+
+ printf "Proceed with commit? (y/n): "
+ read yn < /dev/tty
+
+ [ "$yn" == "${yn#[Yy]}" ] && return 1
+
+ return 0
+}
+
+# run grammar check
+check_grammar
+
+if [ $? -ne 0 ]; then
+ printf "Aborted.\n"
+ exit 1
+fi