fix(config_help): normalize keyword and heading before matching

The previous grep pattern required an exact substring match, so
"keybindings" failed to match the heading "KEY BINDINGS". Normalize
both the user keyword and each heading line by stripping all
non-alphanumeric characters and lowercasing before comparing, so
"keybindings" → "keybindings" matches "KEY BINDINGS" → "keybindings",
"fish-deps" matches "fish-deps", etc.
This commit is contained in:
2026-06-06 03:39:53 -04:00
parent 41e801eab1
commit 63fc4bb6be
+14 -1
View File
@@ -34,9 +34,22 @@ function config_help --description 'Open the offline fish shell configuration ma
end
# ── Resolve section start line ───────────────────────────────
# Normalize both sides: strip non-alphanumeric chars and lowercase.
# This lets "keybindings" match "KEY BINDINGS", "fish-deps" match
# "fish-deps", etc. without requiring exact punctuation or case.
set -l start_line 1
if test -n "$argv[1]"
set -l found (grep -n -im 1 "^#\+.*$argv[1]" "$doc_file" | cut -d: -f1)
set -l norm_kw (string lower -- $argv[1] | string replace -ra '[^a-z0-9]' '')
set -l found ""
for entry in (grep -n "^#" "$doc_file")
set -l lnum (string split -f 1 ':' -- $entry)
set -l text (string split -f 2- ':' -- $entry)
set -l norm_text (string lower -- $text | string replace -ra '[^a-z0-9]' '')
if string match -q "*$norm_kw*" $norm_text
set found $lnum
break
end
end
if test -n "$found"
set start_line $found
else