mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-03-17 20:28:03 +02:00
zsh: support sourcing zsh completion dynamically
Previously, you needed to save the completion script to a file and then source it. Now, you can dynamically source completions in zsh by running $ source <(rg --generate complete-zsh) Before this commit, you would get an error after step 1. After this commit, it should work as expected. We also improve the FAQ item for zsh completions. Fixes #2956
This commit is contained in:
parent
79cbe89deb
commit
94305125ef
23
FAQ.md
23
FAQ.md
@ -94,7 +94,7 @@ Does ripgrep have support for shell auto-completion?
|
|||||||
|
|
||||||
Yes! If you installed ripgrep through a package manager on a Unix system, then
|
Yes! If you installed ripgrep through a package manager on a Unix system, then
|
||||||
the shell completion files included in the release archive should have been
|
the shell completion files included in the release archive should have been
|
||||||
installed for you automatically. If not, you can generate completes using
|
installed for you automatically. If not, you can generate completions using
|
||||||
ripgrep's command line interface.
|
ripgrep's command line interface.
|
||||||
|
|
||||||
For **bash**:
|
For **bash**:
|
||||||
@ -113,14 +113,31 @@ $ mkdir -p "$dir"
|
|||||||
$ rg --generate complete-fish > "$dir/rg.fish"
|
$ rg --generate complete-fish > "$dir/rg.fish"
|
||||||
```
|
```
|
||||||
|
|
||||||
For **zsh**:
|
For **zsh**, the recommended approach is:
|
||||||
|
|
||||||
```
|
```zsh
|
||||||
$ dir="$HOME/.zsh-complete"
|
$ dir="$HOME/.zsh-complete"
|
||||||
$ mkdir -p "$dir"
|
$ mkdir -p "$dir"
|
||||||
$ rg --generate complete-zsh > "$dir/_rg"
|
$ rg --generate complete-zsh > "$dir/_rg"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
And then add `$HOME/.zsh-complete` to your `fpath` in, e.g., your
|
||||||
|
`$HOME/.zshrc` file:
|
||||||
|
|
||||||
|
```zsh
|
||||||
|
fpath=($HOME/.zsh-complete $fpath)
|
||||||
|
```
|
||||||
|
|
||||||
|
Or if you'd prefer to load and generate completions at the same time, you can
|
||||||
|
add the following to your `$HOME/.zshrc` file:
|
||||||
|
|
||||||
|
```zsh
|
||||||
|
$ source <(rg --generate complete-zsh)
|
||||||
|
```
|
||||||
|
|
||||||
|
Note though that while this approach is easier to setup, is generally slower
|
||||||
|
than the previous method, and will add more time to loading your shell prompt.
|
||||||
|
|
||||||
For **PowerShell**, create the completions:
|
For **PowerShell**, create the completions:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -434,7 +434,15 @@ _rg_types() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_rg "$@"
|
# Don't run the completion function when being sourced by itself.
|
||||||
|
#
|
||||||
|
# See https://github.com/BurntSushi/ripgrep/issues/2956
|
||||||
|
# See https://github.com/BurntSushi/ripgrep/pull/2957
|
||||||
|
if [[ $funcstack[1] == _rg ]] || (( ! $+functions[compdef] )); then
|
||||||
|
_rg "$@"
|
||||||
|
else
|
||||||
|
compdef _rg rg
|
||||||
|
fi
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# ZSH COMPLETION REFERENCE
|
# ZSH COMPLETION REFERENCE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user