diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index c7d6a07..82bc2c2 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -66,3 +66,8 @@ entry: pre_commit_hooks/main.sh check-chinese language: script types_or: [markdown] +- id: check-title-initial + name: Check if the first letter of the title is capitalized + entry: pre_commit_hooks/main.sh check-title-initial + language: script + types_or: [markdown] diff --git a/pre_commit_hooks/check-title-initial.sh b/pre_commit_hooks/check-title-initial.sh new file mode 100755 index 0000000..0c3e1cd --- /dev/null +++ b/pre_commit_hooks/check-title-initial.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +check() { + local ret=0 + + # Check if the first letter of the title is capitalized + if grep -qE '^# [a-z]' "$1" >/dev/null + then + ret=1 + echo "$1: First letter of the title should be capitalized" >&2 + if ! $DRY_RUN + then + sed -i -E 's/^# ([a-z])/# \U\1/' "$1" + fi + fi + + return $ret +}