fix(config_help): use ANSI-aware section delimiter for bat+ov pipeline

bat emits Markdown headers as ESC[<color>m# so the raw ^# regex never
matches. Use ^(\x1b\[[0-9;]*m)+# instead — matches one or more ANSI
escape sequences before the # regardless of theme or color depth.
Restores section navigation (,/.) while keeping bat syntax highlighting.
This commit is contained in:
2026-06-06 03:24:11 -04:00
parent 76d651b0de
commit 1a752c4c87
+9 -5
View File
@@ -47,14 +47,18 @@ function config_help --description 'Open the offline fish shell configuration ma
end
# ── Viewer fallback chain ────────────────────────────────────
# Best case: bat provides syntax color, ov provides paging + line jump.
# Section nav (,/.) is sacrificed when piping bat output because ANSI
# escape codes prevent ^# matching; use / to search instead.
# Best case: bat colors the output; ov matches headers in the ANSI stream
# via a regex that skips the escape codes preceding each '#'.
# bat emits headers as: ESC[<color>m# ... so we match ^(ESC\[[0-9;]*m)+#
# This is theme-agnostic (works for any 8/24-bit color sequence) and
# gives us both syntax highlighting AND section navigation (,/.).
if type -q ov; and type -q bat
bat --color=always --style=plain --language=markdown "$doc_file" \
| ov --jump-target "$start_line"
| ov --section-delimiter "^(\x1b\[[0-9;]*m)+#" \
--section-header \
--jump-target "$start_line"
# ov alone: full section navigation with ,/. keys; no code highlighting.
# ov alone: section navigation on raw Markdown; no code highlighting.
else if type -q ov
ov --section-delimiter "^#" \
--section-header \