Zoxide – A faster alternative to boring cd command

Zoxide – A faster alternative to boring cd command

Why Zoxide is a better replacement??

Best way to start explainning is to show how we normally navigate using the good old cd command.

Now you might think that “hey, can’t we just use up arrow key or an autocomplete plugin?”.

Well, those might perform very well when working with simple folder structures, but imagine having to press up arrow key thousands of times to get to your previously used directory that wanted to navigate to.

And also in the case of auto-complte plugin, it will also leave a very unreadable number of lines in the terminal that might confuse you refer back the previous lines of your terminal for reviewing something.

That’s where Zoxide excels!

Both of those problems can be easily be eliminated just by installing Zoxide to your terminal.

Now let’s see how we do the same operation using Zoxide.

Pretty easy right?

Well if you have multiple folders with the same name in different directories there are two ways you can use zoxide to get to the exact one you want.

Method 1 – If you are on a compatible shell version of bash,zsh or fish you will be automatically prompted with the available directories for that folder name as follows.

Method 2 – If for some reason you don’t get the above feature, you can use another famous tool called fzf (aka fuzzy finder). With the power of fzf you can use the below command to show all the directories saved with that perticular folder name. You can even take a peak at the content inside that folder.

Not only that there are many other ways you can customize the commands. You’ll find a very detailed instruction set in their official repo which I have linked at the end of this article.

Actually Zoxide ins’t the first program that provided these facilities. There were earlier programs which are still up-to-date named z, autojump and fasd. While autojump and fasd are way more advanced than Zoxide, they also have a more steep learning curve.

In terms of simplicity and lightweightness, Zoxide is the best option out of all. On top of that, Zoxide is built on Rust which makes it blazing fast.

Belive me you won’t even notice that you’re using a third party tool.

Okay now we’ll see how to install this into your favourite terminal.

Zoxide will work with any linux terminal including Windows and MacOS. Infact it is available through almost any package manager you have heard, used or seen.

For linux/MacOS

Although the official documentation of Zoxide recommends using package installers or managers, I would highly suggest you to use curl to get the install script and install.

curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash

For Windows

Zoxide works really well with Powershell in Windows.

Use winget package manager to install Zoxide.

winget install ajeetdsouza.zoxide

Post install steps (only for Linux/MacOS)

Open your configuration file related your termial using a code editor.

# Assuming you are on zsh and using nano as the code editor
nano .zshrc

Add the following line to the end of the file to initialize Zoxide with your terminal.

eval “$(zoxide init zsh)”

(skip this step if it is already in the file)

Now add following line to add the Zoxide install directory to the PATH which helps you to use the z command in every directory of your termial.

export PATH=”/Users/chamalrandika/.local/bin:$PATH”

Source the configuration file to invoke the changes.

source .zshrc

Install fzf (if multiple directory handling didn’t work with the default z synax)

clone the official repo to get the install script.

git clone –depth 1 https://github.com/junegunn/fzf.git ~/.fzf

Install

~/.fzf/install

Add this line to configuation file as explained in previous steps to reduce the width of the suggestions window (default is 100%)

export FZF_DEFAULT_OPTS=’–height 40%’

Source the configuration file.

More information

You can refer the official documentation if you are an advaced user or just curious to know more about the projects.

Zoxide offical GitHub repo – https://github.com/ajeetdsouza/zoxide

fzf official GitHub repo – https://github.com/junegunn/fzf

That’s it!

Happy CLI life devs ✌️