Improved cdf function

This commit is contained in:
Yan Lin 2025-08-27 20:54:41 +02:00
parent 844fa8070e
commit 385e50a560

View file

@ -113,14 +113,10 @@ in
# Function to cd to directory containing a file selected with fzf # Function to cd to directory containing a file selected with fzf
function cdf() { function cdf() {
local file local target
file=$(fd "$@" ~ | fzf) 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 "$file" ]]; then if [[ -n "$target" ]]; then
if [[ -d "$file" ]]; then [[ -d "$target" ]] && cd "$target" || cd "$(dirname "$target")"
cd "$file"
else
cd "$(dirname "$file")"
fi
fi fi
} }
''; '';