<article>
<style>
hr.thin {
    border: 0;
    height: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}
</style>
<h2 id="overview">Overview</h2>
<p>I like the idea that there are tools available to enhance the
<code>'cd'</code> command, remembering places you have been in the file
system and taking you there easily.</p>
<p>I use <a
href="https://hackerpublicradio.org/eps.php?id=1843"><code>'pushd'</code>
and <code>'popd'</code></a> 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 <code>cd</code> have always seemed desirable.</p>
<p>I was using <code>'autojump'</code> 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.</p>
<p>Recently I heard of <code>'zoxide'</code>, which I have been trying
and really like.</p>
<hr class="thin">
<h2 id="zoxide"><code>zoxide</code></h2>
<h3 id="what-is-it">What is it?</h3>
<p>From the <a href="https://github.com/ajeetdsouza/zoxide">GitHub
page</a>:</p>
<blockquote>
<p>zoxide is a smarter cd command, inspired by z<a href="#fn1"
class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a> and
autojump.</p>
<p>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.</p>
</blockquote>
<p>In its man page it’s billed as “A faster way to navigate your
filesystem”.</p>
<p>It’s written in <code>Rust</code> so is very fast.</p>
<h3 id="what-does-it-do">What does it do?</h3>
<ul>
<li><p>It offers the functionality of the Linux/Unix <code>'cd'</code>
command.</p></li>
<li><p>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 <em>frecency</em> to do this - a combination of
frequency and recency. (<a
href="https://en.wikipedia.org/wiki/Frecency">See the Wikipedia page
explaining this word</a>)</p></li>
<li><p>It performs algorithmic matching on the directory you specify and
takes you to the highest ranking best match.</p></li>
<li><p>It can resolve conflicts between matching directories or can
allow selection through an interactive interface.</p></li>
<li><p>It can interface to <code>fzf</code>, a general-purpose
command-line fuzzy finder.</p></li>
<li><p>It “knows” where it is (in the Bash shell) by calling a function
out of the <code>PROMPT_COMMAND</code> 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 <em>hook</em> monitoring commands into
a Bash session.</p></li>
</ul>
<h3 id="where-can-you-get-it">Where can you get it?</h3>
<p>I installed it from the Debian Testing repo, but I got
<code>'zoxide v0.4.3-unknown'</code> whereas the latest version is
0.9.0. Installing from the <a
href="https://github.com/ajeetdsouza/zoxide">GitHub page</a> seems the
best option if you want the latest version.</p>
<p>There is an installation script on the GitHub page and it’s possible
to download it with <code>curl</code> and pipe it to Bash. I’m never
comfortable doing this, but that’s your choice.</p>
<p>I also installed <code>fzf</code> from the Debian Testing repo,
though I’m still learning what this can do, since it’s very rich in
features!</p>
<h3 id="how-do-you-set-it-up">How do you set it up?</h3>
<p>This process is shell-specific. I run Bash so I have added it to my
<code>~/.bashrc</code> and the command there is:</p>
<pre><code>eval &quot;$(zoxide init bash)&quot;</code></pre>
<p>What this does is generate a number of Bash functions and aliases and
some commands which are fed into <code>eval</code> and executed in the
current context.</p>
<p>Function <code>z</code> is created which gives a way of invoking
<code>zoxide</code> in fewer keystrokes, though the full functionality
of <code>zoxide</code> is not available through this function, use the
full <code>zoxide</code> command.</p>
<p>Function <code>zi</code> lists all of the stored directories courtesy
of <code>fzf</code>. I haven’t tested this without <code>fzf</code>, 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 <code>Enter</code> 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.</p>
<h3 id="how-to-tune-it">How to tune it?</h3>
<p>The <code>zoxide</code> behaviour can be modified through environment
variables (and at setup time).</p>
<p>For example it is possible to define directories which are not to be
stored using the environment variable <code>_ZO_EXCLUDE_DIRS</code>.
This must be done before running <code>zoxide init</code>. In my case, I
have the following in my <code>~/.bashrc</code>:</p>
<pre><code>export _ZO_EXCLUDE_DIRS=&quot;/media/extras:/media/extras/*&quot;
eval &quot;$(zoxide init bash)&quot;</code></pre>
<p>The setup details are to be found in the GitHub documentation.</p>
<h2 id="conclusion">Conclusion</h2>
<p>I really like this. It’s fast and configurable, and with
<code>fzf</code> gives some great command-line features. There are
editor plugins, such as <code>zoxide.vim</code> for Vim and Neovim (not
used yet). It also integrates with other third-party tools.</p>
<p>It seems to be the best of its type!</p>
<h2 id="links">Links</h2>
<ul>
<li>HPR show <a
href="https://hackerpublicradio.org/eps.php?id=1843">“hpr1843 :: Some
Bash tips”</a> covers <code>pushd</code>, <code>popd</code> and
<code>dirs</code>.</li>
<li><a href="https://github.com/ajeetdsouza/zoxide"><code>zoxide</code>
GitHub page</a></li>
<li><a href="https://github.com/junegunn/fzf"><code>fzf</code> GitHub
page</a></li>
<li><a href="https://en.wikipedia.org/wiki/Frecency">Wikipedia page on
the word <em>frecency</em></a></li>
<li><a href="https://github.com/rupa/z">The <code>'z'</code> tool on
GitHub</a></li>
<li><a href="https://github.com/wting/autojump">The
<code>'autojump'</code> tool on GitHub</a></li>
</ul>
<section class="footnotes footnotes-end-of-document"
role="doc-endnotes">
<hr />
<ol>
<li id="fn1" role="doc-endnote"><p>I didn’t know what <code>'z'</code>
was when recording the audio. I did some research and found it, and can
see how <code>'zoxide'</code> has similar behaviour. I have added a link
in case you want to investigate this yourself.<a href="#fnref1"
class="footnote-back" role="doc-backlink">↩︎</a></p></li>
</ol>
</section>
</article>
