zoxide - A faster alternative to boring cd command
Tags: cli, linux, bash, zsh
Published: 2024-05-19 04:08:55

### Why zoxide is a better replacement??

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

![Usual cd command usage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m1wy5leuhbuo7to2omwa.png)

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-complete plugin, it will also leave a very unreadable number of lines in the terminal that might confuse you when you referring 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.

![zoxide navigate command usage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/du8dh20ek00z5nrptjql.png)

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.

![Multiple directories on zoxide method 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/px40knt1xb26l7s7pd8a.png)

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 particular folder name. You can even take a peak at the content inside that folder.

![Multiple directories on zoxide method 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iexafmtjzb6rqo1yt10o.png)

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 isn'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.

Believe 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 favorite 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.

```bash
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.

```sh
winget install ajeetdsouza.zoxide
```

#### Post install steps (only for Linux/MacOS)

1. Open your configuration file related your terminal using a code editor.

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

2. 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)

3. 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 terminal.

`export PATH="/Users/chamalrandika/.local/bin:$PATH"`

4. Source the configuration file to invoke the changes.

```bash
source .zshrc
```

#### Install fzf (if multiple directory handling didn't work with the default z syntax)

1. clone the official repo to get the install script.

```bash
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
```

2. Install

```bash
~/.fzf/install
```

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

`export FZF_DEFAULT_OPTS='--height 40%'`

4. Source the configuration file.

### More information

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

-   zoxide official GitHub repo - https://github.com/ajeetdsouza/zoxide
-   fzf official GitHub repo - https://github.com/junegunn/fzf

That's it!

Happy CLI life devs. ✌️