zsh: Add $fzf_default_no_rg

Move the fallback for $FZF_DEFAULT_COMMAND into the variable
fzf_default_no_rg that is always set.

This way FZF_ALT_C_COMMAND can reuse it instead of spawning a new shell
and messing with PATH.
This commit is contained in:
2022-09-19 13:01:30 +02:00
parent ed1bfc6ebf
commit 181971c1db
2 changed files with 10 additions and 11 deletions

View File

@@ -90,18 +90,20 @@ LESS+="${LESS:+ }--RAW-CONTROL-CHARS"
LESS+="${LESS:+ }--quit-if-one-screen"
export LESS
# NOTE: This is used in keys.zsh for the ALT_C widget
fzf_default_no_rg="find -L . -mindepth 1 \("
fzf_default_no_rg+=" -name '.git' -o"
fzf_default_no_rg+=" -name '__pycache__' -o"
fzf_default_no_rg+=" -name 'node_modules'"
fzf_default_no_rg+=" \) -prune -o -type f -print"
fzf_default_no_rg+=" | cut -c3-"
if (( $+commands[rg] )); then
# Prune `.git/` and everything ignored by gitignore(5)
FZF_DEFAULT_COMMAND="rg -L --hidden --files -g '!.git'"
else
# Fallback to hardcoding the most important paths to prune
# NOTE: This version is used in keys.zsh for the ALT_C widget
FZF_DEFAULT_COMMAND="find -L . -mindepth 1 \("
FZF_DEFAULT_COMMAND+=" -name '.git' -o"
FZF_DEFAULT_COMMAND+=" -name '__pycache__' -o"
FZF_DEFAULT_COMMAND+=" -name 'node_modules'"
FZF_DEFAULT_COMMAND+=" \) -prune -o -type f -print"
FZF_DEFAULT_COMMAND+=" | cut -c3-"
FZF_DEFAULT_COMMAND="$fzf_default_no_rg"
fi
export FZF_DEFAULT_COMMAND

View File

@@ -140,8 +140,5 @@ bindkey -M vicmd '^K' fzf-history-widget
FZF_CTRL_T_COMMAND="${FZF_DEFAULT_COMMAND}"
# Use the fallback default command when ripgrep is not installed but with
# directories instead of files.
FZF_ALT_C_COMMAND="$(
zsh -c 'path= . "$ZDOTDIR/.zprofile"; echo "$FZF_DEFAULT_COMMAND"' \
| sed 's/-type f/-type d/'
)"
FZF_ALT_C_COMMAND="${fzf_default_no_rg/-type f/-type d}"
comp-source "$ZDOTDIR/plugins/fzf/shell/key-bindings.zsh"