diff --git a/2025/06/fzf-with-fd-and-beyond.md b/2025/06/fzf-with-fd-and-beyond.md new file mode 100644 index 0000000..67d7840 --- /dev/null +++ b/2025/06/fzf-with-fd-and-beyond.md @@ -0,0 +1,90 @@ +# Why You Might Use `fzf` with `fd`—and Beyond + +At first glance, `fzf` looks like a simple fuzzy finder for your terminal. You type part of a string, and it finds the best matches in a list. That alone is powerful—but not enough. To use `fzf` effectively, you need to feed it good data. That’s where tools like `fd` come in. + +## The Role of `fd`: Clean Input for Better Output + +`fd` is a modern replacement for `find`. It's faster, more intuitive, and designed to work well with other command-line tools. While `fzf` handles fuzzy selection, `fd` generates the list of items you can select from. This separation of concerns is critical. + +Compare: + +```bash +fzf +```` + +This opens `fzf` with no input. It waits for something to search. You can type, but it does nothing useful. + +Now: + +```bash +fd . | fzf +``` + +`fd` recursively lists all files from the current directory. `fzf` then allows you to quickly pick the one you want. Together, they create an interactive file navigation system that’s faster and more flexible than a GUI. + +## Real World: Beyond File Navigation + +The power of `fzf` extends far beyond picking files: + +### 1. **Git Workflow Enhancement** + +```bash +git checkout $(git branch | fzf) +``` + +Quickly switch branches without remembering exact names. + +### 2. **Command History Search** + +```bash +history | fzf +``` + +Find a previously used command without paging through history. + +### 3. **Process Management** + +```bash +ps aux | fzf | awk '{print $2}' | xargs kill +``` + +Fuzzy-select a process to kill without manually finding the PID. + +### 4. **SSH Host Selection** + +```bash +cat ~/.ssh/known_hosts | cut -d',' -f1 | fzf | xargs ssh +``` + +Choose a remote host to connect to from your known SSH entries. + +### 5. **Running Scripts** + +```bash +ls ~/scripts | fzf | xargs -I{} bash ~/scripts/{} +``` + +Select a script to execute from a collection. + +### 6. **Systemd Service Control** + +```bash +systemctl list-units --type=service --all | fzf | awk '{print $1}' | xargs systemctl restart +``` + +Interactively restart a systemd service. + +## Why Pairing Matters + +`fzf` alone is an interface. What makes it useful is your data source. The better your source list, the more powerful your workflow. `fd`, `git`, `ps`, `ls`, `systemctl`, and even `cat` can be used as upstream providers to create dynamic, contextual interfaces with minimal overhead. + +Use `fzf` as a control mechanism: a selector for lists you define. Then pipe the output into whatever action you want to take. + +## Summary + +* `fzf` is a universal interface for selecting from a list. +* `fd` is a fast, modern file generator—perfect as input to `fzf`. +* The pairing allows efficient, focused file management. +* Outside of files, `fzf` improves speed, clarity, and precision in virtually every shell task involving lists. + +If you ever find yourself repeating grep or `cat` into `awk` to get a list just to copy and paste something—consider using `fzf` instead.