Why zoxide is a better replacement??
Best way to start explaining 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-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.
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 particular 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 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.
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 terminal 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 terminal.
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 syntax)
- 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 configuration 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 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. ✌️
Top comments (3)
cd -
, which should be a familiar convention if you've used other commands likegit
, etc.CDPATH
is a simple way of managing preferred directories, and is built-in as part of POSIX.ctrl-R
or the equivalent.I mention these because they show how you can do most of what Zoxide offers without installing anything. I mean, of course you can install whatever you like, but Zoxide won't be available on the machine you ssh into next week, or your co-worker's laptop, etc., whereas the basics will. It's that as a top tip to newbies, it's usually a good idea to familiarise yourself with what's already there, then add on utilities to fit your productivity style afterwards.
Thanks a lot man I didn't know about these. You're a total neckbeard I see. I mean zoxide offering what native commands can do with less keystrokes. Just like how Vim offers vimgrep and regex commands to code refactor or you can use some LSP plugins to do the same. There will be always a built in method to do 90% of the things in most scenarios in POXIS systems. These are just a tool to customize your shell experience and impress the friends a lil bit.
Thank you. As a newcomer, your words of wisdom are invaluable.