Skip to content

Add Windows-native which command - #59

Open
曹梦轩 (caomengxuan666) wants to merge 3 commits into
microsoft:mainfrom
caomengxuan666:winuxcmd/which
Open

Add Windows-native which command#59
曹梦轩 (caomengxuan666) wants to merge 3 commits into
microsoft:mainfrom
caomengxuan666:winuxcmd/which

Conversation

@caomengxuan666

@caomengxuan666 曹梦轩 (caomengxuan666) commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Adds a small Windows-native which implementation.

It searches PATH, respects PATHEXT on Windows, supports -a/--all, and returns a non-zero exit code when any requested command is not found.

This came out of the scope discussion in #56: which is common on Unix/macOS and fills a small PowerShell gap without needing a POSIX layer.

Validation:

  • cargo test -p uu_which
  • cargo check
  • target\debug\coreutils.exe which powershell

Closes #154

@lhecker Leonard Hecker (lhecker) added the C-feature Feature requests and any other major tasks. label Jun 9, 2026

@IDisposable Marc Brooks (IDisposable) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@lhecker

Copy link
Copy Markdown
Member

From what I can tell, the code is significantly more efficient now. We can't do much about the performance of Win32 APIs of course.

The biggest issue that remains with this PR is that the actual which command is much more feature rich:

Usage: which [options] [--] COMMAND [...]
Write the full path of COMMAND(s) to standard output.

  --version, -[vV] Print version and exit successfully.
  --help,          Print this help and exit successfully.
  --skip-dot       Skip directories in PATH that start with a dot.
  --skip-tilde     Skip directories in PATH that start with a tilde.
  --show-dot       Don't expand a dot to current directory in output.
  --show-tilde     Output a tilde for HOME directory for non-root.
  --tty-only       Stop processing options on the right if not on tty.
  --all, -a        Print all matches in PATH, not just the first
  --read-alias, -i Read list of aliases from stdin.
  --skip-alias     Ignore option --read-alias; don't read stdin.
  --read-functions Read shell functions from stdin.
  --skip-functions Ignore option --read-functions; don't read stdin.

I'm inclined to merge it anyway, however. I still hesitate because not complying to GNU here would be a bad precedent (uutil's differences to GNU coreutils is already an issue on its own and much less bad).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-feature Feature requests and any other major tasks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add which

3 participants