From 1cf3877ba53432b7a917981d50dd17ca778da5bc Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Fri, 29 Aug 2025 12:58:53 +0200 Subject: [PATCH] Add pwdf function --- README.md | 8 ++++++++ config/projects.nix | 2 +- modules/zsh.nix | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 32ed498..61c0fbb 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,8 @@ hms # Quick home-manager switch (rebuild) # Directory navigation helpers cdf # Interactive file/directory search with real-time preview # Type to search, Enter to cd to selection or parent +pwdf # Same as cdf but prints the full path instead of cd + # Returns file path for files, directory path for dirs # Application launcher app [file] # Interactive macOS app selector with fzf @@ -465,6 +467,12 @@ zi && fd "*.md" | fzf # Interactive directory select, then find markdown file cdf # Type to search files/directories across your home # Shows preview of directories and file contents # Enter to cd to selection or its parent directory + +# Get file/directory path without changing location +pwdf # Search and print full path +cp "$(pwdf)" . # Copy selected file +cat "$(pwdf)" # Read selected file +cd "$(dirname "$(pwdf)")" # cd to parent of selected file ``` #### Built-in zsh keybindings: diff --git a/config/projects.nix b/config/projects.nix index 10f73ac..2ec9d6f 100644 --- a/config/projects.nix +++ b/config/projects.nix @@ -38,7 +38,7 @@ in name = "note"; path = homePath "Obsidian/Personal"; ai = true; - git = true; + git = false; shell = false; } ]; diff --git a/modules/zsh.nix b/modules/zsh.nix index 9239754..5f52c26 100644 --- a/modules/zsh.nix +++ b/modules/zsh.nix @@ -106,6 +106,15 @@ in fi } + # Function to print path of file/directory selected with fzf + function pwdf() { + local target + target=$(echo "" | fzf --bind "change:reload:fd --hidden --follow --exclude .git {q} ~ 2>/dev/null || true" --header="Type to search, Enter to print path" --preview '([[ -d {} ]] && ls -la {}) || ([[ -f {} ]] && head -20 {})' --height 40% --ansi) + if [[ -n "$target" ]]; then + echo "$target" + fi + } + # Function to search and open all macOS applications function app() { local app_path