From 385e50a5602e5df36ddb763207f7a1150153af75 Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Wed, 27 Aug 2025 20:54:41 +0200 Subject: [PATCH] Improved cdf function --- modules/zsh.nix | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/modules/zsh.nix b/modules/zsh.nix index f54cf92..e19bc56 100644 --- a/modules/zsh.nix +++ b/modules/zsh.nix @@ -113,14 +113,10 @@ in # Function to cd to directory containing a file selected with fzf function cdf() { - local file - file=$(fd "$@" ~ | fzf) - if [[ -n "$file" ]]; then - if [[ -d "$file" ]]; then - cd "$file" - else - cd "$(dirname "$file")" - fi + local target + target=$(echo "" | fzf --bind "change:reload:fd --hidden --follow --exclude .git {q} ~ 2>/dev/null || true" --header="Type to search, Enter to cd" --preview '([[ -d {} ]] && ls -la {}) || ([[ -f {} ]] && head -20 {})' --height 40% --ansi) + if [[ -n "$target" ]]; then + [[ -d "$target" ]] && cd "$target" || cd "$(dirname "$target")" fi } '';