just do everything i guess

This commit is contained in:
atagen 2026-03-29 16:40:36 +11:00
parent 1e7b7d1614
commit 34ae680e69
5 changed files with 277 additions and 22 deletions

View file

@ -868,7 +868,15 @@ let cmd_index bindirs mandirs ignorelist help_only dir =
let subdir = Filename.concat mandir (Printf.sprintf "man%d" section) in
if is_dir subdir then begin
let files = Sys.readdir subdir in
Array.sort String.compare files;
(* sort by filename length first, then alphabetically.
* this ensures parent manpages (e.g. nix-env.1.gz) are
* processed before subpage manpages (nix-env-install.1.gz)
* so the parent's data isn't overwritten by a subpage
* whose synopsis also extracts the parent command name. *)
Array.sort (fun a b ->
let la = String.length a and lb = String.length b in
if la <> lb then compare la lb
else String.compare a b) files;
Array.iter (fun file ->
let base_cmd = cmd_name_of_manpage file in
if SSet.mem base_cmd help_only then ()
@ -879,7 +887,12 @@ let cmd_index bindirs mandirs ignorelist help_only dir =
write_result ~dir ~source:"manpage" cmd result;
done_cmds := SSet.add cmd !done_cmds;
incr result_count
end;
end else if cmd <> base_cmd then
(* a subpage manpage (e.g. nix-env-install.1) extracted
* a command name that was already indexed (e.g. "nix-env").
* warn so the user can investigate. *)
Printf.eprintf "warning: %s extracted cmd \"%s\" (already indexed), skipping\n"
file cmd;
List.iter (fun (sub_cmd, sub_result) ->
if not (SSet.mem sub_cmd !done_cmds) then begin
write_result ~dir ~source:"manpage" sub_cmd sub_result;
@ -1041,7 +1054,10 @@ let find_real_command is_command args =
* this ensures file completions appear with full nushell UX. when the user
* IS typing a flag (partial starts with "-"), we return our flag candidates. *)
let cmd_complete spans user_dir system_dirs mandirs =
let dirs = user_dir :: system_dirs in
(* system dirs are searched first — they're built at index time from
* manpages and are authoritative. user dir is an on-the-fly cache
* that should only be used as fallback for commands not in any system dir. *)
let dirs = system_dirs @ [user_dir] in
(* if the command line starts with a privilege-escalation wrapper, scan past
* it to find the real command. we identify the command by checking the store
* and $PATH this avoids needing per-command option tables which are fragile