Expand description
native_cmds submodule — builtins contributed by the linking binary
(the fat zshrs-native build registers git / arb / stryke here).
Host-registered native commands — builtins contributed by the binary
rather than by this library.
EXT_BUILTIN_NAMES (extensions/ext_builtins.rs) and the daemon’s
ZSHRS_BUILTIN_NAMES are both compile-time lists owned by this crate. A
fat binary that links sibling runtimes into the shell’s address space —
zshrs-native links zvcs (git), arblang (arb) and strykelang
(stryke) — has no way to extend either: they are const arrays, and the
runtimes cannot be dependencies of this crate (zvcs depends on its own
vendored gitoxide by path, which makes any dependent unpublishable).
So the binary registers them here, once, before the shell starts. A
registered name dispatches in-process on a direct function call: no fork,
no execve, no PATH walk, no dynamic loader — the same treatment cat and
sort already get from reg_overridable!.
§Dispatch order
Registration does not jump the queue. zsh resolves a command word as alias → function → builtin → external (c:Src/exec.c:3038-3068), and a native command sits in the builtin slot, after the ported builtin table:
- a user
git() { … }still wins, exactly as it shadowscattoday; command gitstill reaches whatevergitis onPATH, because the forced-external path never consults this registry;builtin gitreaches the native one.
§Registration is one-shot and start-up only
The table is written once by the binary’s main before the shell runs and
is read from every command dispatch after that, including from the worker
threads. It is therefore an RwLock whose write side is expected to be
uncontended: registering after startup is allowed but pointless, and no
path ever removes an entry — a name that answered whence -w one moment
must not vanish the next.
Structs§
- Forced
External Guard - Restores the previous
command-prefix state on drop, so a nested dispatch (acommandinside a function a native command ran) unwinds correctly instead of leaving the flag stuck on.
Functions§
- dispatch
- Run
namewithargv(argv[0] included) if it is registered. - force_
external - Mark the current invocation as
command-forced for as long as the returned guard lives. - is_
enabled - Registered and not masked by
disable NAME. - is_
forced_ external - True while a
command NAMEprecommand is dispatching NAME, i.e. while the user has explicitly asked for thePATHbinary rather than this table. - is_
registered - Is
namea host-registered native command? - names
- Every registered name, sorted. Feeds the
builtinsmagic assoc (${(k)builtins}),whence -m, and compsys’s command-position completion, so the shell reports the same set it will actually dispatch. - register
- Register
nameas a native command backed byf.
Type Aliases§
- Native
Cmd - A native command body: the full argv (argv[0] is the command name, as invoked) in, a wait-status-style exit code out.