whi
Stupid simple PATH management
whi is a powerful which replacement with PATH manipulation. Find executables, see all matches, and reorder your PATH with simple shell commands.
Features
- Better than which: Shows winner by default, all matches with
-a - PATH manipulation: Move, swap, and prefer executables with shell integration
- Winner indication: Clearly marks which executable would actually run with color
- PATH indices (
-i): Shows the PATH index for each match - Full PATH listing (
-f): Displays complete PATH with indices - Follow symlinks (
-l): Resolves and shows canonical targets - File metadata (
-s): Shows inode, device, size, and modification time - Combinable flags: Unix-style flag combining (e.g.,
-ais,-ifl) - Pipe-friendly: Quiet by default, all output to stdout
- Zero dependencies: Only libc for isatty(3)
Installation
Or build from source:
Quick Start
Shell Integration (Recommended)
whi provides shell integration that gives you commands to manipulate your PATH directly in your current shell session. Without shell integration, whi --move and similar commands would only output a new PATH string - they can't modify your actual shell's PATH variable.
To enable shell integration, add this to your shell config:
Bash (~/.bashrc):
Zsh (~/.zshrc):
Fish (~/.config/fish/config.fish):
whi init fish | source
The whi init <shell> command outputs shell-specific functions that you can evaluate/source. This provides five powerful commands:
-
whim FROM TO- Move PATH entry from index FROM to index TO -
whis IDX1 IDX2- Swap two PATH entries -
whip NAME INDEX- Make executable at INDEX win (prefer it over others) -
whia NAME- Show all matches with indices (shortcut forwhi -ia) -
whii [NAME]- Show PATH entries or matches with indices (shortcut forwhi -i)
These commands actually modify your current shell's PATH environment variable, so changes take effect immediately without restarting your shell or sourcing config files
Basic Usage
View all PATH entries (with or without indices):
Find an executable (like which) - shows only the winner:
See all matches with -a:
With PATH indices using -i (or use whia cargo shortcut):
Follow symlinks with -l to see what they point to:
Show detailed metadata with -s:
Combine flags for all matches with indices and symlinks:
PATH Manipulation Examples
See which cargo is winning and make a different one win:
Move PATH entries to reorder them:
Swap two PATH entries:
Other Usage Examples
Read multiple names from stdin:
|
Check multiple executables at once:
Show all PATH entries (with or without indices):
Use custom PATH:
Command-Line Options
Flags
Short flags can be combined Unix-style (e.g., -ai = -a -i, -ais = -a -i -s).
-a, --all- Show all PATH matches (default: only winner)-f, --full- Show all matches + full PATH listing (implies-a; directories with matches highlighted in color)-i, --index- Show PATH index next to each entry-l, -L, --follow-symlinks- Resolve and show canonical targets-o, --one- Only print the first match per name-s, --stat- Include inode/device/mtime/size metadata-0, --print0- NUL-separated output for use with xargs-q, --quiet- Suppress non-fatal stderr warnings--silent- Print nothing to stderr, use exit codes only--show-nonexec- Also list files that exist but aren't executable-h, --help- Print help information
PATH Manipulation
These commands output a modified PATH string to stdout. Use shell integration (see above) to actually modify your current shell's PATH.
-
--move <FROM> <TO>- Move PATH entry from index FROM to index TO -
--swap <IDX1> <IDX2>- Swap PATH entries at indices IDX1 and IDX2 -
--prefer <NAME> <INDEX>- Make executable NAME at INDEX win
Other Options
-
--path <PATH>- Override environment PATH string -
--color <WHEN>- Colorize output:auto,never,always[default: auto]
Shell Integration Command
whi init <SHELL>- Output shell integration code for bash, zsh, or fish
Exit Codes
0- All names found1- At least one not found2- Usage error3- I/O or environment error
Examples
Find all versions of Python in PATH:
Check which node would run with indices:
Use with xargs to check executables:
|
Find all versions with metadata:
Show all PATH entries with indices:
Comparison with which
| Feature | which |
whi |
|---|---|---|
| Show first match | ✓ | ✓ (default) |
| Show all matches | Some versions with -a |
✓ With -a |
| Show PATH indices | ✗ | ✓ With -i |
| Full PATH listing | ✗ | ✓ With -f |
| Follow symlinks | Some versions | ✓ With -l/-L |
| File metadata | ✗ | ✓ With -s |
| PATH manipulation | ✗ | ✓ With shell integration |
| Combinable flags | ✗ | ✓ |
| Multiple names | ✓ | ✓ |
| Stdin input | ✗ | ✓ |
| Pipe-friendly | Varies | ✓ |
Why?
Ever wonder:
- Which version of
pythonornodeis actually running? - How to make a different version win without editing shell configs?
- What other versions exist on your PATH?
- What's the actual order of your PATH directories?
whi answers all these questions and lets you manipulate your PATH on the fly with simple shell commands.
License
MIT
Author
Alexander Knott alexander.knott@posteo.de