You might want to replace cd command with Zoxide πŸŽ‰ β€” a smarter and trainable cd alternative πŸ—‚οΈ

creuser - Mar 9 - - Dev Community

Have you ever encountered a problem where you kept changing directories, costing you a lot of time? I certainly have.

But guess what? I found something called Zoxide, and it has revolutionized the way I navigate through my directories. It saves me time, helps me stay focused, and boosts my productivity.

How does it work?

Essentially, it's no different from the cd command. However, after using it for a while, you'll come to appreciate its efficiency.

Let's say you want to open your project directory. This is how you'd do it with the cd command:

$ cd creuserr/projects/my_project
Enter fullscreen mode Exit fullscreen mode

With Zoxide, it's just as simple:

$ z creuserr/projects/my_project
Enter fullscreen mode Exit fullscreen mode

As I mentioned earlier, it's essentially the same as cd.

$ cd -
$ z -

$ cd ..
$ z ..

$ cd /
$ z /
Enter fullscreen mode Exit fullscreen mode

However, after navigating through these directories, Zoxide will remember them all.

For example, after navigating to the my_project directory and closing the terminal, you can return to it using just keywords:

$ z my_project
creuserr/projects/my_project $
Enter fullscreen mode Exit fullscreen mode

Pretty cool, right? Give it a try!

Installation

Head over to ajeetdsouza/zoxide and install it now! It's innovative, free, and flexible!

How to use it?

You can only use shortcuts if Zoxide recognizes the directory.

$ z blah blah
zoxide: no match found
Enter fullscreen mode Exit fullscreen mode

You can also navigate with multiple keywords.

$ z creuserr my_project
creuserr/projects/my_project $
Enter fullscreen mode Exit fullscreen mode

Moreover, there are some algorithms you should know about:

Algorithms

1. Case Insensitivity

Zoxide is case insensitive when searching for directories by keywords.

$ z My_PROJECT
creuserr/projects/my_project $
Enter fullscreen mode Exit fullscreen mode

2. Two or More Keywords Do Not Recognize Sub-directories

It's a bit tricky, but here's an example:

$ z foo/bar/baz/lorem/ipsum
foo/bar/baz/lorem/ipsum $

$ z bar
foo/bar $

$ z baz ipsum
foo/bar/baz/lorem/ipsum $

$ z foo baz
zoxide: no match found
Enter fullscreen mode Exit fullscreen mode

Basically, you can only navigate with two or more keywords if the last keyword corresponds to a recognized directory.

3. Unordered Keyword Stacks Are Not Supported

$ z foo/bar/baz/lorem/ipsum
foo/bar/baz/lorem/ipsum $

$ z baz foo
zoxide: no match found

$ z lorem foo
zoxide: no match found
Enter fullscreen mode Exit fullscreen mode

Navigation with keywords must follow a left-to-right order.

How It Works Under the Hood

Recognized directories are stored with a frecency score, which determines their priority level when the user searches for something.

Frecency: Frequency + Recency

Frecency is a term coined from frequency and recency. Frecency scores are determined by how frequently the user navigates to a directory and how long ago the last visit was.

When a user navigates to a directory, its frecency score increases by 1, and the recency is determined by the last time it was accessed.

Last Time Access Frecency
Within the Last Hour score * 4
Within the Last Day score * 2
Within the Last Week score / 2
Otherwise score / 4
$ z foo/bar/baz
$ z lorem/ipsum/baz

Imagine foo/bar/baz has a higher frecency score than lorem/ipsum/baz.

$ z baz
foo/bar/baz $
Enter fullscreen mode Exit fullscreen mode

Thank you for reading this blog! I hope you find it helpful! Please consider leaving a react or a comment; I would really appreciate it! ❀️

. . . . .