DEV Community

Luxcih
Luxcih

Posted on

Say good bye to cd and hello Zoxide - the better and smarter cd command!

Introduction

If you're like me, you're constantly zipping around directories in your terminal, trying to keep up with your coding projects, side hustles, and random tech adventures. But let's be real for a second: the old cd command? It's feels like trying to navigate a maze blindfolded.

Zoxide

https://github.com/ajeetdsouza/zoxide

So, I stumbled upon this game-changing tool that's about to revolutionize the way you navigate your terminal: Zoxide. It works like magic in your terminal. It keeps track of the directories you frequently visit and ranks them based on your usage patterns. So, when you need to navigate to a directory, instead of wracking your brain trying to recall its exact path, you simply type z <directory_name> and voila! Zoxide intelligently takes you there in an instant.

Installation

https://github.com/ajeetdsouza/zoxide#installation

Install binary

Installing Zoxide is a breeze. You can grab it from your favorite package manager or build it from source - whatever floats your boat.

The recommended way to install zoxide is via the install script:

$ curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

I use Arch BTW, so I'll install it using pacman:

$ sudo pacman -S zoxide
Enter fullscreen mode Exit fullscreen mode

Setup zoxide

Once installed, just add a tiny snippet to the end of your shell configuration file (like .bashrc or .zshrc), and you're good to go!

For bash (~/.bashrc):

eval "$(zoxide init bash)"
Enter fullscreen mode Exit fullscreen mode

For fish (~/.config/fish/config.fish):

zoxide init fish | source
Enter fullscreen mode Exit fullscreen mode

For zsh (~/.zshrc):

eval "$(zoxide init zsh)"
Enter fullscreen mode Exit fullscreen mode

Usage

https://github.com/ajeetdsouza/zoxide/wiki/Algorithm
You can find out more about Zoxide on its man page after installed:

$ man zoxide

To unlock its full potential, it's a good idea to train it. Training Zoxide involves simply using your terminal as you normally would for a bit, letting Zoxide observe your directory navigation patterns. Try navigating to your projects with Zoxide.

After training, using Zoxide is as easy as typing z <directory_name> to quickly navigate to frequently accessed directories without the full path!

Rebinding

Now, Zoxide is incredible, no doubt about it. But what if you're a creature of habit, like me, who's been typing cd for eons?

You can easily rebind the z command to cd, so you don't have to mess with your muscle memory:

For bash (~/.bashrc):

eval "$(zoxide init --cmd cd bash)"
Enter fullscreen mode Exit fullscreen mode

For fish (~/.config/fish/config.fish):

zoxide init --cmd cd fish | source
Enter fullscreen mode Exit fullscreen mode

For zsh (~/.zshrc):

eval "$(zoxide init --cmd cd zsh)"
Enter fullscreen mode Exit fullscreen mode

Conclusion

In short, Zoxide is your terminal's new best friend, guiding you effortlessly through directories with just a few keystrokes. Say goodbye to aimless navigation and hello to smooth sailing with Zoxide!

PS: This is my first blog, so your feedback means the world to me!

Top comments (10)

Collapse
 
moopet profile image
Ben Sinclair

I don't particularly like learning commands which enhance (or worse, shadow) existing commands, because I worry I'll lean on their behaviour in a script or on a foreign system and cause something bad to happen.

My issue with Zoxide is that I use a lot of directories with similar names in parallel hierarchies. Lots of similar projects.

When I have to type pwd after every directory change, or create an alias/function to do that for me, and devote extra braincells to pausing and checking before running the next potentially destructive command, I lose productivity.

I don't even like using CDPATH - and that's part of POSIX!

But if it works for you, great :)

Collapse
 
jankapunkt profile image
Jan Küster

I immediately think of adduser as extension to useradd

Collapse
 
onenemo profile image
OneNemo • Edited

Nice article. Straight forward without a lot of preamble or hyperbole. Though in the future you might want to give examples for installation on multiple distros such as Fedora and Ubuntu for people not so familiar with Gnu/Linux.

For instance to install on Fedora 39:

$ sudo dnf install zoxide
Enter fullscreen mode Exit fullscreen mode

and of course add:

eval "$(zoxide init bash)"
Enter fullscreen mode Exit fullscreen mode

to your .bash_profile or .bashrc file.

You could also mention that they can find out more about zoxide on its man page after installed.

$ man zoxide
Enter fullscreen mode Exit fullscreen mode

I like the way you included information about other shells. Good job.

Looking forward to your future articles.

Take Care

Collapse
 
luxcih profile image
Luxcih • Edited

Thank you so much, I'll take this into consideration.

Collapse
 
siph profile image
Chris Dawkins

If you're really adventurous you can try rpg-cli

Collapse
 
thomastaylor profile image
Thomas Taylor

Haha, thanks for this! I didn't know it existed.

Collapse
 
counterpoint profile image
Martin Brampton

Neat - thanks for posting. I'm trying it out - looks good.

Collapse
 
bart97coder profile image
Bart97coder

Intresting post

Collapse
 
ccoveille profile image
Christophe Colombier

Zoxide is a great tool. I'm using it for years, and I couldn't leave without it

Collapse
 
django-webdev profile image
Django Web Dev

zoxide f* rules.