Level Up Your Terminal Game: Quick Project Switching with fzf
codenio

codenio @codenio

About: Open Source Contributor DevOps Enthusiast

Location:
Bangalore
Joined:
Oct 11, 2019

Level Up Your Terminal Game: Quick Project Switching with fzf

Publish Date: Jun 1
0 0

Originally posted on my blog - codenio.hashnode.dev

Ever find yourself typing cd ~/workspace/client-project/backend for the hundredth time? Let's fix that.

Here's a bash function that'll help (or at least save you some keystrokes):

projects(){ 
    # If '-o' or '--open' flag is passed, open selected project in VS Code
    if [[ $* == *-o* ||  $* == *--open* ]]; then
        # List projects in ~/workspace/demo/projects and select one with fzf
        repo=`command ls ~/workspace/demo/projects | fzf --height=50% --layout=reverse` 
        echo $repo
        # Open the selected project folder in VS Code
        code ~/workspace/demo/projects/$repo

    # If '-c' or '--cd' flag is passed, change directory to selected project
    elif [[ $* == *-c* || $* == *--cd* ]]; then
        # Change to projects directory first
        cd ~/workspace/demo/projects
        # Select a project folder with fzf
        repo=`command ls | fzf --height=50% --layout=reverse` 
        echo $repo
        # Change directory into the selected project
        cd $repo

    # If no flags passed, just change directory to projects folder
    else
        cd ~/workspace/demo/projects
    fi
Enter fullscreen mode Exit fullscreen mode

What's This Magic? 🪄

Drop this in your .bashrc or .zshrc, and you get three superpowers:

  • projects → Jump to your projects folder
  • projects -c → Fuzzy-find and cd into any project
  • projects -o → Open any project in VS Code

Quick project switching with fzf

Why This Rocks 🎸

Sure, you could:

  • Set up 50 different aliases (and update them constantly)
  • Use tab completion (and type half the path anyway)
  • Install a fancy terminal (and learn a whole new tool)

Or... just use this tiny function that:

  • Works with your existing setup
  • Leverages fzf's awesome fuzzy search
  • Stays out of your way

Pro Tips 💡

  • Customize the base path (~/workspace/demo/projects) to match your setup
  • Add more flags for different actions (git operations, running tests, etc.)
  • Use --height=50% to control how much screen space fzf takes

That's It!

No fancy frameworks. No complex setup. Just a simple hack that makes project navigation easy.

Already using fzf? This'll fit right in. Never tried it? Here's your excuse to start.

Happy hacking! ⚡️

Comments 0 total

    Add comment