From 0a7b9c85ae33fb40ad57c855f45eebcae4dbb98b Mon Sep 17 00:00:00 2001 From: David Morgan Date: Fri, 6 Sep 2024 14:36:00 +0100 Subject: Speed up/improve fzf config --- nix-conf/home/includes/zsh.nix | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'nix-conf/home/includes') diff --git a/nix-conf/home/includes/zsh.nix b/nix-conf/home/includes/zsh.nix index 5ca4eab..34a2bb7 100644 --- a/nix-conf/home/includes/zsh.nix +++ b/nix-conf/home/includes/zsh.nix @@ -6,6 +6,7 @@ }: let inherit (lib) optionalAttrs optionals; + show_file_or_dir_preview = "if [ -d {} ]; then eza --tree --color=always {} | head -200; else bat -n --color=always --line-range :500 {}; fi"; in { home.packages = with pkgs; [ zsh-completions ]; @@ -117,10 +118,11 @@ in LESS = "-iRXF"; - FZF_DEFAULT_COMMAND = ''rg --files --no-ignore --hidden --follow -g \"!{.git,node_modules}/*\" 2> /dev/null''; + FZF_DEFAULT_COMMAND = "fd --hidden --strip-cwd-prefix --exclude .git --exclude node_modules"; FZF_CTRL_T_COMMAND = config.programs.zsh.localVariables.FZF_DEFAULT_COMMAND; - FZF_ALT_C_COMMAND = ''rg --hidden --files --sort-files --null -g \"!{.git,node_modules}/*\" | xargs -0 dirname | sort -u''; - FZF_ALT_C_OPTS = "--preview 'eza --tree {} | head -200'"; + FZF_CTRL_T_OPTS = "--preview '${show_file_or_dir_preview}'"; + FZF_ALT_C_COMMAND = "fd --type=d --hidden --strip-cwd-prefix --exclude .git --exclude node_modules"; + FZF_ALT_C_OPTS = "--preview 'eza --tree --color=always {} | head -200'"; FZF_CTRL_R_OPTS = "--preview 'echo {}' --preview-window down:3:hidden:wrap --bind 'ctrl-t:toggle-preview'"; FZF_DEFAULT_OPTS = "--bind=ctrl-t:toggle-all --bind=ctrl-j:jump"; }; @@ -164,6 +166,25 @@ in # switch group using `,` and `.` zstyle ':fzf-tab:*' switch-group ',' '.' + # functions modified from https://www.josean.com/posts/7-amazing-cli-tools + _fzf_compgen_path() { + fd --hidden --exclude .git --exclude node_modules . "$1" + } + _fzf_compgen_dir() { + fd --type=d --hidden --exclude .git --exclude node_modules . "$1" + } + _fzf_comprun() { + local command=$1 + shift + + case "$command" in + cd) fzf --preview 'eza --tree --color=always {} | head -200' "$@" ;; + export|unset) fzf --preview "eval 'echo $'{}" "$@" ;; + ssh) fzf --preview 'dig {}' "$@" ;; + *) fzf --preview "${show_file_or_dir_preview}" "$@" ;; + esac + } + set -o noclobber # disable flow control (so that fzf-git.sh's ^g^s can work) -- cgit 1.4.1-2-gfad0 le='author Kartik K. Agaram <vc@akkartik.com> 2021-12-03 20:55:32 -0800 committer Kartik K. Agaram <vc@akkartik.com> 2021-12-03 20:55:32 -0800 elaborate a little more on install instructions' href='/akkartik/teliva/commit/shell.nix?id=294c135d3ffd8e937bef404703695d7d79599f8e'>294c135 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19