#!/usr/bin/env bash # Lookup a term or usage guidance in the Google Style Guide word-list.md. # Usage: ./lookup-word.sh set -euo pipefail if [[ $# -eq 0 ]]; then echo "Usage: $(basename "$0") " >&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"