Repository navigation
feat(which): add which, resolved like command -v - #272
Merged
Merged
Conversation
Collaborator
Author
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
Collaborator
There was a problem hiding this comment.
@ferdingler, here's the review you asked for. TL;DR: this is good to merge after one small fix. The command -v/-V refactor behaves exactly as it did before. The one issue is that which gives wrong answers for names that contain / (which /bin/ls and which ./s both exit 1), and the fix is three lines (inline).
✅ What I verified
- Head
6c0d043, compared against a build oforigin/mainat5f80040. cargo test --test shell_integration --test command_fallbackgives 1972 + 28 passed. With the inline suggestion applied, I re-ran it and still got 1972 + 28 passed.- I checked the refactor's equivalence by reading the code.
lookup_command(.., true)keeps the old order: special, builtin, registered command, fallback (only when no function exists), function, hash, PATH. The-Vlabels are unchanged. - I ran more than 20
whichprobes by hand:-awith dedup, functions skipped,-aa,--, missing names, an emptyPATH, an unsetPATH, a directory onPATH, and a stale hash entry (matchescommand -v). All behave as described in the PR.
Questions (non-blocking)
- Bare name for built-ins. Agents often use the output as a path:
x=$(which ls); [ -x "$x" ]is false, and so isls -l "$(which ls)". When a/bin/<name>link exists and is first onPATH, printing that link would match GNU/just-bash. I understand the choice to matchcommand -v; I'm just flagging the tradeoff.
Appendix: non-blocking (3)
- ⚪
src/builtins/which.rs:32:which --all lsprintswhich: --: invalid option, because the error names--instead of--all. Accepting--allor naming the whole argument would read better. - ⚪ Pre-existing, not filed:
command -v /bin/lsandcommand -v ./salready exit 1 onmain. The inline fix covers this too, so a separate issue isn't needed. - ⚪ Pre-existing: README says "25 builtins" (
README.md:118,:252), butmainalready has more. Optional to fix here.
Routing: I ran a single correctness/tests reviewer pass and my own probes. I skipped the API pass because there's no SDK/binding surface change, and the adversarial pass because there's no parsing, concurrency or security path.
3 tasks done
Collaborator
Author
|
Thanks for the review. Pushed 2b86cd9:
|
10 tasks done
This was referenced Nov 17, 2026
opieter-aws
approved these changes
Nov 17, 2026
1 task done
8 of 10 tasks
9 of 10 tasks
10 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Agents reach for
whichall the time to check whether a tool is installed, and the shell didn't have it, so those checks always said the tool was missing even when it would run fine.This adds
which. It finds names the same waycommand -vdoes (built-in commands, builtins, names a command fallback serves, and scripts on PATH), so the two never disagree about what exists. Like the real one, it doesn't report shell functions. It takes several names and-afor every match on PATH, exits 0 only when all names are found, and prints nothing for a missing name. For a built-in command likelsit printsls, the same ascommand -v, rather than a path. just-bash prints/usr/bin/lsthere, but our/bin/lsis only a link back into the shell, and-astill shows it after the bare name.I added tests for the cases above, including one that checks
whichandcommand -vgive the same answer and a few with a command fallback. I also ran it by hand against scripts on PATH and a function. The full Rust check passes locally. I didn't run the Python or Node tests since this doesn't touch the bindings.Related Issues
Part of #207
Documentation PR
None
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.