11#! /bin/ksh
2- set -eu
2+
3+ # If we are NOT already running under ksh93, try to re-exec with ksh93.
4+ # If ksh93 is not available, fall back to the base ksh (OpenBSD /bin/ksh).
5+ case " ${KSH_VERSION-} " in
6+ * 93* ) : ;; # already ksh93
7+ * )
8+ if command -v ksh93 > /dev/null 2>&1 ; then
9+ exec ksh93 " $0 " " $@ "
10+ elif [ -x /usr/local/bin/ksh93 ]; then
11+ exec /usr/local/bin/ksh93 " $0 " " $@ "
12+ elif command -v ksh > /dev/null 2>&1 ; then
13+ exec ksh " $0 " " $@ "
14+ elif [ -x /bin/ksh ]; then
15+ exec /bin/ksh " $0 " " $@ "
16+ fi
17+ ;;
18+ esac
19+
20+ set -u
321
422# Script to format HTML files using tidy
523#
6- # Copyright (c) 2025 The Cyberpunk Handbook Authors
24+ # Copyright (c) 2025 David Uhden Collado <david@uhden.dev>
725#
826# Permission to use, copy, modify, and distribute this software for any
927# purpose with or without fee is hereby granted, provided that the above
@@ -17,11 +35,19 @@ set -eu
1735# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1836# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1937
20- # Prefer ksh93 when available; fallback to base ksh
21- if [ -z " ${_KSH93_EXECUTED:- } " ] && command -v ksh93 > /dev/null 2>&1 ; then
22- _KSH93_EXECUTED=1 exec ksh93 " $0 " " $@ "
38+ # Basic PATH (important when run from cron)
39+ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
40+ export PATH
41+
42+ if [ -t 1 ] && [ " ${NO_COLOR:- } " != " 1" ]; then
43+ GREEN=" \033[32m" ; YELLOW=" \033[33m" ; RED=" \033[31m" ; RESET=" \033[0m"
44+ else
45+ GREEN=" " ; YELLOW=" " ; RED=" " ; RESET=" "
2346fi
24- _KSH93_EXECUTED=1
47+
48+ log () { print " $( date ' +%Y-%m-%d %H:%M:%S' ) ${GREEN} [INFO]${RESET} ✅ $* " ; }
49+ warn () { print " $( date ' +%Y-%m-%d %H:%M:%S' ) ${YELLOW} [WARN]${RESET} ⚠️ $* " >&2 ; }
50+ error () { print " $( date ' +%Y-%m-%d %H:%M:%S' ) ${RED} [ERROR]${RESET} ❌ $* " >&2 ; }
2551
2652ROOT=${1:- $(cd -- " $( dirname -- " $0 " ) /.." && pwd)}
2753
@@ -31,26 +57,33 @@ ensure_tidy() {
3157 fi
3258
3359 if command -v pkg_add > /dev/null 2>&1 ; then
34- print " tidy not found; attempting installation with pkg_add ..." >&2
60+ warn " tidy not found; attempting installation with pkg_add ..."
3561 if pkg_add -v tidy; then
3662 return 0
3763 fi
38- print " error: pkg_add failed to install tidy" >&2
64+ error " pkg_add failed to install tidy"
3965 else
40- print " error: tidy is not installed and pkg_add is unavailable" >&2
66+ error " tidy is not installed and pkg_add is unavailable"
4167 fi
4268
4369 return 1
4470}
4571
46- ensure_tidy || exit 1
47-
48- # find on OpenBSD lacks -print0; use newline delim and handle spaces via IFS
49- find " $ROOT " -type f -name ' *.html' | while IFS= read -r file; do
50- tidy -indent -quiet -wrap 0 -utf8 \
51- --indent-spaces 2 \
52- --tidy-mark no \
53- --preserve-entities yes \
54- --vertical-space yes \
55- -modify " $file " || echo " warning: tidy issues in $file " >&2
56- done
72+ format_html_files () {
73+ # find on OpenBSD lacks -print0; use newline delim and handle spaces via IFS
74+ find " $ROOT " -type f -name ' *.html' | while IFS= read -r file; do
75+ tidy -indent -quiet -wrap 80 -utf8 \
76+ --indent-spaces 2 \
77+ --tidy-mark no \
78+ --preserve-entities yes \
79+ --vertical-space yes \
80+ -modify " $file " || warn " tidy issues in $file "
81+ done
82+ }
83+
84+ main () {
85+ ensure_tidy || exit 1
86+ format_html_files
87+ }
88+
89+ main " $@ "
0 commit comments