mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
b304de8199
* Detect built-in commands passed as args to `which` This expands the built-in `which` command to detect nushell commands that may have the same name as a binary in the path. * Allow which to interpret multiple arguments Previously, it would discard any argument besides the first. This allows `which` to process multiple arguments. It also makes the output a stream of rows. * Use map to build the output * Add boolean column for builtins * Use macros for entry creation shortcuts * Process command args and use async_stream In order to use `ichwh`, I'll need to use async_stream. But in order to avoid lifetime errors with that, I have to process the command args before using them. I'll admit I don't fully understand what is going on with the `args.process(...)` function, but it works. * Use `ichwh` for path searching This commit transitions from `which` to `ichwh`. The path search is now done asynchronously. * Enable the `--all` flag on `which` * Make `which` respect external commands Escaped commands passed to wich (e.g., `which "^ls"`), are now searched before builtins. * Fix clippy warnings This commit resolves two warnings from clippy, in light of #1142. * Update Cargo.lock to get new `ichwh` version `ichwh@0.2.1` has support for local paths. * Add documentation for command
3.3 KiB
3.3 KiB
which
Finds a program file.
Usage:
which ...args{flags}
Parameters
- ...args: the names of the commands to find the path to
- --all: list all executables
Examples
which
finds the location of an executable:
/home/bob> which python
━━━━━━━━┯━━━━━━━━━━━━━━━━━┯━━━━━━━━━
arg │ path │ builtin
────────┼─────────────────┼─────────
python │ /usr/bin/python │ No
━━━━━━━━┷━━━━━━━━━━━━━━━━━┷━━━━━━━━━
/home/bob> which cargo
━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━
arg │ path │ builtin
───────┼────────────────────────────┼─────────
cargo │ /home/bob/.cargo/bin/cargo │ No
━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━
which
will identify nushell commands:
/home/bob> which ls
━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━
arg │ path │ builtin
─────┼──────────────────────────┼─────────
ls │ nushell built-in command │ Yes
━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━
/home/bob> which which
━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━
arg │ path │ builtin
───────┼──────────────────────────┼─────────
which │ nushell built-in command │ Yes
━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━
Passing the all
flag identifies all instances of a command or binary
/home/bob> which ls --all
━━━┯━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━
# │ arg │ path │ builtin
───┼─────┼──────────────────────────┼─────────
0 │ ls │ nushell built-in command │ Yes
1 │ ls │ /usr/bin/ls │ No
━━━┷━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━
which
will also identify local binaries
/home/bob> touch foo
/home/bob> chmod +x foo
/home/bob> which ./foo
━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━
arg │ path │ builtin
───────┼───────────────┼─────────
./foo │ /home/bob/foo │ No
━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━