Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at


hpr3836 :: Using 'zoxide', an alternative to 'cd'

Dave has been using 'zoxide' for a little while and really likes it

<< First, < Previous, , Latest >>

Thumbnail of Dave Morriss
Hosted by Dave Morriss on 2023-04-17 is flagged as Explicit and is released under a CC-BY-SA license.
directory, folder, change directory, cd, zoxide, autojump. (Be the first).
The show is available on the Internet Archive at: https://archive.org/details/hpr3836

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:11:55

Lightweight Apps.

Reviews of light weight applications

Overview

I like the idea that there are tools available to enhance the 'cd' command, remembering places you have been in the file system and taking you there easily.

I use 'pushd' and 'popd' for moving in and out of directories from a place I want to do most of my work, but something more powerful than these or cd have always seemed desirable.

I was using 'autojump' for a while last year, but didn’t really get on with it. This was mainly because there was no way of excluding certain directories which had been visited from its list.

Recently I heard of 'zoxide', which I have been trying and really like.


zoxide

What is it?

From the GitHub page:

zoxide is a smarter cd command, inspired by z1 and autojump.

It remembers which directories you use most frequently, so you can “jump” to them in just a few keystrokes. zoxide works on all major shells.

In its man page it’s billed as “A faster way to navigate your filesystem”.

It’s written in Rust so is very fast.

What does it do?

  • It offers the functionality of the Linux/Unix 'cd' command.

  • It collects the directories you have visited into a database and gives them a ranking relating to the number of times they have been visited. It applies aging rules and removes these when the ranking drops below one. It uses frecency to do this - a combination of frequency and recency. (See the Wikipedia page explaining this word)

  • It performs algorithmic matching on the directory you specify and takes you to the highest ranking best match.

  • It can resolve conflicts between matching directories or can allow selection through an interactive interface.

  • It can interface to fzf, a general-purpose command-line fuzzy finder.

  • It “knows” where it is (in the Bash shell) by calling a function out of the PROMPT_COMMAND variable. This can be used to execute one or more commands before displaying the prompt for a new command. This is a common way to hook monitoring commands into a Bash session.

Where can you get it?

I installed it from the Debian Testing repo, but I got 'zoxide v0.4.3-unknown' whereas the latest version is 0.9.0. Installing from the GitHub page seems the best option if you want the latest version.

There is an installation script on the GitHub page and it’s possible to download it with curl and pipe it to Bash. I’m never comfortable doing this, but that’s your choice.

I also installed fzf from the Debian Testing repo, though I’m still learning what this can do, since it’s very rich in features!

How do you set it up?

This process is shell-specific. I run Bash so I have added it to my ~/.bashrc and the command there is:

eval "$(zoxide init bash)"

What this does is generate a number of Bash functions and aliases and some commands which are fed into eval and executed in the current context.

Function z is created which gives a way of invoking zoxide in fewer keystrokes, though the full functionality of zoxide is not available through this function, use the full zoxide command.

Function zi lists all of the stored directories courtesy of fzf. I haven’t tested this without fzf, so I’m not sure what it does if it’s not available. The scrollable list can be navigated and a directory chosen with the Enter key (or double mouse click). In the scrollable list, if characters are typed they are used to select directories from the list, so that it’s simple to find a directory whose exact name you have forgotten.

How to tune it?

The zoxide behaviour can be modified through environment variables (and at setup time).

For example it is possible to define directories which are not to be stored using the environment variable _ZO_EXCLUDE_DIRS. This must be done before running zoxide init. In my case, I have the following in my ~/.bashrc:

export _ZO_EXCLUDE_DIRS="/media/extras:/media/extras/*"
eval "$(zoxide init bash)"

The setup details are to be found in the GitHub documentation.

Conclusion

I really like this. It’s fast and configurable, and with fzf gives some great command-line features. There are editor plugins, such as zoxide.vim for Vim and Neovim (not used yet). It also integrates with other third-party tools.

It seems to be the best of its type!


  1. I didn’t know what 'z' was when recording the audio. I did some research and found it, and can see how 'zoxide' has similar behaviour. I have added a link in case you want to investigate this yourself.↩︎


Comments

Subscribe to the comments RSS feed.

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
What is the HOST_ID for the host of this show?
What does HPR mean to you?