From d21d685090be53d916ec869c040be98c49347782 Mon Sep 17 00:00:00 2001 From: rootiest Date: Sat, 6 Jun 2026 04:06:46 -0400 Subject: [PATCH] fix(config_help): slice file from start_line instead of using --pattern --section-header pins section-delimiter lines as sticky headers, which removes them from ov's pattern search scope. --pattern "# 3. KEY BINDINGS" therefore reports "not found" even though the line exists. Replace --pattern with tail -n +$start_line piped before ov. The file naturally starts at the target section so no search is needed, section nav (Space/^) still works for all subsequent sections, and the sidebar is populated correctly via --section-delimiter "^#". --- functions/config_help.fish | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/functions/config_help.fish b/functions/config_help.fish index dfbcde8..6e58232 100644 --- a/functions/config_help.fish +++ b/functions/config_help.fish @@ -10,6 +10,9 @@ # If a section keyword is provided, the pager opens at the first heading # that matches the keyword. Lookup order: docs/fish-config.index (exact # keyword aliases), then a normalized heading scan as fallback. +# When jumping to a section the file is sliced from that line onwards so +# ov never has to search through section-header lines (which --section-header +# pins and hides from pattern matching). # # ARGUMENTS # section Optional keyword to jump to a matching section heading @@ -35,15 +38,15 @@ function config_help --description 'Open the offline fish shell configuration ma return 1 end - # ── Resolve section ────────────────────────────────────────── + # ── Resolve section start line ─────────────────────────────── # 1. Look up keyword in fish-config.index (keyword → exact heading text). # 2. Fall back to normalized scan of heading lines if not in index. # 3. Resolve start_line via grep -F on the heading text (immune to line # number drift — only breaks if the heading itself is renamed). set -l start_line 1 - set -l found_text "" if test -n "$argv[1]" set -l norm_kw (string lower -- $argv[1] | string replace -ra '[^a-z0-9]' '') + set -l found_text "" # ── Index lookup ───────────────────────────────────────── if test -f "$idx_file" @@ -85,28 +88,34 @@ function config_help --description 'Open the offline fish shell configuration ma end # ── Viewer fallback chain ──────────────────────────────────── - # ov matches section-delimiter against logical (displayed) text, so "^#" - # works on bat-colored output — no ANSI regex needed. + # When jumping to a section, slice the file from start_line so ov + # opens with that section at the top without needing --pattern. + # --pattern on section-delimiter lines is unreliable: --section-header + # pins those lines as sticky headers, removing them from search scope. # Section nav: Space (next), ^ (previous), Alt+u (section list sidebar). - # --pattern uses the exact heading text for a precise one-line match. if type -q ov; and type -q bat set -l ov_args \ --section-delimiter "^#" \ --section-header - if test -n "$found_text" - set -a ov_args --pattern (string escape --style=regex -- $found_text) + if test $start_line -gt 1 + bat --color=always --style=plain --language=markdown "$doc_file" \ + | tail -n +$start_line \ + | ov $ov_args + else + bat --color=always --style=plain --language=markdown "$doc_file" \ + | ov $ov_args end - ov $ov_args (bat --color=always --style=plain --language=markdown "$doc_file" | psub) # ov alone: section navigation on raw Markdown; no code highlighting. else if type -q ov set -l ov_args \ --section-delimiter "^#" \ --section-header - if test -n "$found_text" - set -a ov_args --pattern (string escape --style=regex -- $found_text) + if test $start_line -gt 1 + tail -n +$start_line "$doc_file" | ov $ov_args + else + ov $ov_args "$doc_file" end - ov $ov_args "$doc_file" # bat alone: syntax highlighting with built-in paging; no line jump. else if type -q bat