From d1e8fe0a0a154544f62fbb9bf858f0ae3acd2c80 Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Sat, 23 Aug 2025 12:09:00 +0800 Subject: [PATCH] Add cdf alias --- README.md | 6 ++++++ modules/zsh.nix | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 1b0a16b..038437c 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,9 @@ g, gs, ga, gc, gp, gl, gd, gco, gb # Git operations # Nix management hm # home-manager shortcut hms # Quick home-manager switch (rebuild) + +# Directory navigation helpers +cdf [pattern] # Find file/directory and cd to its location ``` ### 🖥️ Session Management: Tmux @@ -373,6 +376,9 @@ nvim $(fd --type f | fzf --preview 'bat --color=always {}') # Smart directory navigation with zoxide cd proj && nvim . # Jump to project directory and edit zi && fd "*.md" | fzf # Interactive directory select, then find markdown files + +# Find and navigate to directories containing specific files +cdf "Universal Sparse" # Search for files/dirs matching pattern and cd there ``` #### Built-in zsh keybindings: diff --git a/modules/zsh.nix b/modules/zsh.nix index d0b38fc..805d662 100644 --- a/modules/zsh.nix +++ b/modules/zsh.nix @@ -113,6 +113,19 @@ in # Zoxide configuration - replace cd with z for smart directory jumping eval "$(zoxide init zsh --cmd cd)" + + # 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 + fi + } ''; };