1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-08-04 21:52:54 +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:
Max Coplan
2024-12-31 05:23:13 -08:00
committed by GitHub
parent 79cbe89deb
commit 94305125ef
2 changed files with 29 additions and 4 deletions

View File

@ -434,7 +434,15 @@ _rg_types() {
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