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 "^#".
This commit is contained in:
+20
-11
@@ -10,6 +10,9 @@
|
|||||||
# If a section keyword is provided, the pager opens at the first heading
|
# If a section keyword is provided, the pager opens at the first heading
|
||||||
# that matches the keyword. Lookup order: docs/fish-config.index (exact
|
# that matches the keyword. Lookup order: docs/fish-config.index (exact
|
||||||
# keyword aliases), then a normalized heading scan as fallback.
|
# 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
|
# ARGUMENTS
|
||||||
# section Optional keyword to jump to a matching section heading
|
# 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
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# ── Resolve section ──────────────────────────────────────────
|
# ── Resolve section start line ───────────────────────────────
|
||||||
# 1. Look up keyword in fish-config.index (keyword → exact heading text).
|
# 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.
|
# 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
|
# 3. Resolve start_line via grep -F on the heading text (immune to line
|
||||||
# number drift — only breaks if the heading itself is renamed).
|
# number drift — only breaks if the heading itself is renamed).
|
||||||
set -l start_line 1
|
set -l start_line 1
|
||||||
set -l found_text ""
|
|
||||||
if test -n "$argv[1]"
|
if test -n "$argv[1]"
|
||||||
set -l norm_kw (string lower -- $argv[1] | string replace -ra '[^a-z0-9]' '')
|
set -l norm_kw (string lower -- $argv[1] | string replace -ra '[^a-z0-9]' '')
|
||||||
|
set -l found_text ""
|
||||||
|
|
||||||
# ── Index lookup ─────────────────────────────────────────
|
# ── Index lookup ─────────────────────────────────────────
|
||||||
if test -f "$idx_file"
|
if test -f "$idx_file"
|
||||||
@@ -85,28 +88,34 @@ function config_help --description 'Open the offline fish shell configuration ma
|
|||||||
end
|
end
|
||||||
|
|
||||||
# ── Viewer fallback chain ────────────────────────────────────
|
# ── Viewer fallback chain ────────────────────────────────────
|
||||||
# ov matches section-delimiter against logical (displayed) text, so "^#"
|
# When jumping to a section, slice the file from start_line so ov
|
||||||
# works on bat-colored output — no ANSI regex needed.
|
# 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).
|
# 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
|
if type -q ov; and type -q bat
|
||||||
set -l ov_args \
|
set -l ov_args \
|
||||||
--section-delimiter "^#" \
|
--section-delimiter "^#" \
|
||||||
--section-header
|
--section-header
|
||||||
if test -n "$found_text"
|
if test $start_line -gt 1
|
||||||
set -a ov_args --pattern (string escape --style=regex -- $found_text)
|
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
|
end
|
||||||
ov $ov_args (bat --color=always --style=plain --language=markdown "$doc_file" | psub)
|
|
||||||
|
|
||||||
# ov alone: section navigation on raw Markdown; no code highlighting.
|
# ov alone: section navigation on raw Markdown; no code highlighting.
|
||||||
else if type -q ov
|
else if type -q ov
|
||||||
set -l ov_args \
|
set -l ov_args \
|
||||||
--section-delimiter "^#" \
|
--section-delimiter "^#" \
|
||||||
--section-header
|
--section-header
|
||||||
if test -n "$found_text"
|
if test $start_line -gt 1
|
||||||
set -a ov_args --pattern (string escape --style=regex -- $found_text)
|
tail -n +$start_line "$doc_file" | ov $ov_args
|
||||||
|
else
|
||||||
|
ov $ov_args "$doc_file"
|
||||||
end
|
end
|
||||||
ov $ov_args "$doc_file"
|
|
||||||
|
|
||||||
# bat alone: syntax highlighting with built-in paging; no line jump.
|
# bat alone: syntax highlighting with built-in paging; no line jump.
|
||||||
else if type -q bat
|
else if type -q bat
|
||||||
|
|||||||
Reference in New Issue
Block a user