Skip to content

feat(native_path): resolve the shell tree in API operands (niubash #346) - #1185

Merged
caomengxuan666 merged 2 commits into
mainfrom
fix/niu346-shell-tree
Oct 16, 2026
Merged

caomengxuan666 merged 2 commits into
mainfrom
fix/niu346-shell-tree

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

niubash #346. The bundled coreutils receive the shell's POSIX spellings verbatim, so WinuxCmd now owns the shell namespace instead of leaning on rubash's pre-translation:

  • normalize_api_operand_w resolves the bare / and every path below the configured install root, plus /tmp, /var/tmp, /home and the /mnt/X WSL drive form (shell_tree_to_native_w).
  • canonicalize_path_w re-expresses a shell-namespaced operand's result in the POSIX face (shell_tree_display_w), so readlink -f and realpath agree with the spelling-preserving pwd.
  • The executable-leaf open order (an existing as-spelled path wins, else the X.exe sibling) keeps test -f /usr/bin/seq and head -1 /usr/bin/seq consistent while ls -d keeps the operand spelling (rubash#177).

The mapping mirrors rubash's shell_path_to_windows exactly: /tmp -> TMPDIR else %TEMP%; /var/tmp -> <temp>/var/tmp; /home -> the parent of HOME/USERPROFILE; /mnt/X -> X:\.

Scope / safety

The layer is inert unless a shell root is configured (__RUBASH_SHELL_ROOT / NIU_ROOT / WINUXSH_ROOT / RUBASH_ROOT) — the same gate the bare / case already used — so standalone WinuxCmd keeps its native dialect and a foreign POSIX runtime is unaffected.

Verification

Standalone (shell root configured, invoked directly without a shell):

  • ls -d / /usr/bin /etc /tmp /home /bin /mnt/d renders the POSIX spellings;
  • ls /etc enumerates the shell tree;
  • realpath /usr/bin, readlink -f /etc, realpath /tmp re-express;
  • ls -d /usr/bin/seq resolves seq.exe yet prints /usr/bin/seq;
  • native inputs (realpath ., ls -d C:/Windows) stay native.

Refs unixwin/niubash#346.

niubash #346: the bundled coreutils receive the shell's POSIX spellings
verbatim, so normalize_api_operand_w now resolves the shell tree the same way
rubash's shell_path_to_windows does — the bare "/" and every path below the
configured install root, /tmp, /var/tmp, /home and the /mnt/X WSL drive form —
and canonicalize_path_w re-expresses a shell-namespaced operand's result in the
POSIX face, so readlink -f and realpath agree with the spelling-preserving pwd.

The layer also applies the MSYS open order for executable leaves: an existing
as-spelled path wins, else the X.exe sibling resolves the bare spelling
(rubash#177), so `test -f /usr/bin/seq` and `head -1 /usr/bin/seq` agree while
`ls -d` keeps the operand spelling.

The mapping is inert unless a shell root is configured (the gate the bare "/"
case already used), so standalone WinuxCmd keeps its native dialect and a
foreign POSIX runtime is unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant