blob: 11ec3332b9a727377e8c65ba7f76758accf74dee (
plain)
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
|
#!/usr/bin/env bash
# Lookup a term or usage guidance in the Google Style Guide word-list.md.
# Usage: ./lookup-word.sh <term>
set -euo pipefail
if [[ $# -eq 0 ]]; then
echo "Usage: $(basename "$0") <term>" >&2
exit 1
fi
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
word_list="$script_dir/word-list.md"
if [[ ! -f "$word_list" ]]; then
echo "Error: word-list.md not found at $word_list" >&2
exit 1
fi
pattern="$*"
awk -v pat="$pattern" '
BEGIN { IGNORECASE=1 }
/^- \*\*/ {
if (match_entry) { print entry "\n" }
match_entry = 0
entry = $0
if ($0 ~ pat) match_entry = 1
next
}
{
if (entry != "") entry = entry "\n" $0
if ($0 ~ pat) match_entry = 1
}
END {
if (match_entry) print entry
}
' "$word_list"
|