nushell/docs/commands/which.md
Leonhard Kipp 48f535f02e
Display aliases and custom commands in which; fix #2810 (#2834)
* Display aliases and custom commands in which; Fix #2810

Example output of nu after the commit is applied:

```shell
/home/leo/repos/nushell(feature/which_inspect_alias)> def docker-ps [] { docker ps --format '{{json .}}' | from json -o }
/home/leo/repos/nushell(feature/which_inspect_alias)> which docker-ps
───┬───────────┬────────────────────────┬─────────
 # │    arg    │          path          │ builtin
───┼───────────┼────────────────────────┼─────────
 0 │ docker-ps │ nushell custom command │ No
───┴───────────┴────────────────────────┴─────────
/home/leo/repos/nushell(feature/which_inspect_alias)> alias d = gid pd
/home/leo/repos/nushell(feature/which_inspect_alias)> which d
───┬─────┬───────────────┬─────────
 # │ arg │     path      │ builtin
───┼─────┼───────────────┼─────────
 0 │ d   │ nushell alias │ No
───┴─────┴───────────────┴─────────
```

* Update documentation
2021-01-02 06:40:44 +13:00

106 lines
3.7 KiB
Markdown

# which
Finds a program file.
Usage:
> which <application> {flags}
## Parameters
- application: the name of the command to find the path to
## Flags
- --all: list all executables
## Examples
`which` finds the location of an executable:
```shell
> which python
─────────┬─────────────────
arg │ python
path │ /usr/bin/python
builtin │ No
─────────┴─────────────────
```
```shell
> which cargo
─────────┬────────────────────────────
arg │ cargo
path │ /home/bob/.cargo/bin/cargo
builtin │ No
─────────┴────────────────────────────
```
`which` will identify nushell commands:
```shell
> which ls
─────────┬──────────────────────────
arg │ ls
path │ nushell built-in command
builtin │ Yes
─────────┴──────────────────────────
```
```shell
> which which
─────────┬──────────────────────────
arg │ which
path │ nushell built-in command
builtin │ Yes
─────────┴──────────────────────────
```
Passing the `all` flag identifies all instances of a command or binary
```shell
> which ls --all
───┬─────┬──────────────────────────┬─────────
# │ arg │ path │ builtin
───┼─────┼──────────────────────────┼─────────
0 │ ls │ nushell built-in command │ Yes
1 │ ls │ /bin/ls │ No
───┴─────┴──────────────────────────┴─────────
```
`which` will also identify local binaries
```shell
> touch foo
> chmod +x foo
> which ./foo
─────────┬────────────────────────────────
arg │ ./foo
path │ /Users/josephlyons/Desktop/foo
builtin │ No
─────────┴────────────────────────────────
```
`which` also identifies aliases
```shell
> alias e = echo
> which e
───┬─────┬───────────────┬─────────
# │ arg │ path │ builtin
───┼─────┼───────────────┼─────────
0 │ e │ Nushell alias │ No
───┴─────┴───────────────┴─────────
```
and custom commands
```shell
> def my_cool_echo [arg] { echo $arg }
> which my_cool_echo
───┬──────────────┬────────────────────────┬─────────
# │ arg │ path │ builtin
───┼──────────────┼────────────────────────┼─────────
0 │ my_cool_echo │ Nushell custom command │ No
───┴──────────────┴────────────────────────┴─────────
```