From 181971c1db176f6dada9b19b6601ee409b67c6bc Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Mon, 19 Sep 2022 13:01:30 +0200 Subject: [PATCH] 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. --- .config/zsh/.zprofile | 16 +++++++++------- .config/zsh/zshrc.d/60-keys.zsh | 5 +---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.config/zsh/.zprofile b/.config/zsh/.zprofile index 0d2c964..c97460e 100644 --- a/.config/zsh/.zprofile +++ b/.config/zsh/.zprofile @@ -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 diff --git a/.config/zsh/zshrc.d/60-keys.zsh b/.config/zsh/zshrc.d/60-keys.zsh index 0fff666..a880e1d 100644 --- a/.config/zsh/zshrc.d/60-keys.zsh +++ b/.config/zsh/zshrc.d/60-keys.zsh @@ -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"