posts

Jump To Any Folder Using fzf

 ⚬ 

1 Min Read

Overview

I spend most of my time in the terminal, but switching between different folders, especially finding the projects I am working on, is usually a challenge.

That’s when I thought, why not create a function to fuzzy search and cd into that folder?

The Function

bash
      jumptofolder() {
    cd "$(find -L ~ -type d -maxdepth 5 2>/dev/null \
        | fzf --prompt='open > ' --height=40% --reverse)" 2>/dev/null
}
alias jp='jumptofolder'
    

How It Works

  • find searches the home directory (~) for folders up to a depth of 5.
  • The results are passed to fzf, which provides the fuzzy search.
  • When a folder is selected, the function automatically cds into that directory.

Requirements

You need fzf installed.

For example on arch linux,

bash
      sudo pacman -S fzf
    

Usage

After adding this function to your shell config bashrc or zshrc , you can simply run jp.

Final Thoughts

I’ve been using this for a while now, and it has become a huge lifesaver for me.

Feedback and suggestions

If you find any errors in this post, I'd be happy to fix it. You can reach me through the mail [email protected]

Want to say thank you?