From 1dab31ecdaae156a092a9deaf88236f5a765810f Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Mon, 19 Sep 2022 12:52:00 +0200 Subject: [PATCH] zsh:keys: Reuse the default fallback for FZF_ALT_C Instead of implementing it twice, simulate a shell without ripgrep to get the fallback of FZF_DEFAULT_COMMAND and modify it for use with directories. --- .config/zsh/.zprofile | 1 + .config/zsh/zshrc.d/60-keys.zsh | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.config/zsh/.zprofile b/.config/zsh/.zprofile index 2ef6065..e0ead35 100644 --- a/.config/zsh/.zprofile +++ b/.config/zsh/.zprofile @@ -95,6 +95,7 @@ if (( $+commands[rg] )); then 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 . \(" FZF_DEFAULT_COMMAND+=" -name '.git' -o" FZF_DEFAULT_COMMAND+=" -name '__pycache__' -o" diff --git a/.config/zsh/zshrc.d/60-keys.zsh b/.config/zsh/zshrc.d/60-keys.zsh index 2a956a3..0fff666 100644 --- a/.config/zsh/zshrc.d/60-keys.zsh +++ b/.config/zsh/zshrc.d/60-keys.zsh @@ -138,9 +138,10 @@ bindkey -M vicmd '^K' fzf-history-widget # \ec (Alt-C) fzf-cd-widget # ^R fzf-history-widget FZF_CTRL_T_COMMAND="${FZF_DEFAULT_COMMAND}" -FZF_ALT_C_COMMAND="find -L . -mindepth 1 \(" - FZF_ALT_C_COMMAND+=" -name '.git' -o" - FZF_ALT_C_COMMAND+=" -name '__pycache__' -o" - FZF_ALT_C_COMMAND+=" -name 'node_modules'" -FZF_ALT_C_COMMAND+=" \) -prune -o -type d -print" +# 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/' +)" comp-source "$ZDOTDIR/plugins/fzf/shell/key-bindings.zsh"