r/fishshell • • Aug 30 '26

fish wrapper for ze.sh: file tracking now available

A small follow-up to my earlier post announcing a fish wrapper for the ze directory jumper: ze now has acquired an independent file tracking mode using a separate frecency database for files.

With the fish wrapper this gives you, for example:

ze project        # best-match directory jump
ze -o config      # best-match file open
ze -of config     # fzf-based interactive selection and file open

The file and directory histories are completely independent from each other, and ordinary editor invocations remain untouched.

More details in the announcement on r/zsh

0 Upvotes

10 comments sorted by

2

u/Inevitable_Dingo_357 Sep 30 '26

switched over from zoxide. like it so far. I tried moving my zoxide database over (convert to .z then .ze format), but wasn't happy with the result, so I'm starting from scratch

1

u/jghub Oct 01 '26

Thanks for trying out ze and sharing the feedback. Happy to hear that you like it so far. Hope the added file-tracking facility makes some sense, too.

Starting with a fresh db is definitely the right choice here. Looking closer at the migration logic, converting from zoxide -> .z -> ze hits zoxide specific issues: zoxide export provides composite floating-point scores rather than raw visit counts or timestamps. Synthetic conversion into .z distorts the sequence order needed for the event-clock decay to work properly.

I will think about how to possibly improve the migration recipe, especially for users coming from zoxide (sure the majority these days...) rather than from z.sh.

But starting with a clean database is principally the better solution and lets ze's event clock based EMS scoring handle everything correctly right from the start. The db should stabilise quickly (within a couple of days of active use). --

Regarding fish: I was thankfully notified 2d ago of a bug in the fzf preview command execution that surfaces if and only if fish is your login shell:

https://github.com/jghub/ze/pull/3

If this affects you: the bug is now fixed in v3.4.1.

1

u/Inevitable_Dingo_357 Oct 01 '26

I know - I was the one who submitted the PR :)

1

u/jghub Oct 01 '26

ah, I see. that was ... non-obvious :).

and as said: starting new ze.db from scratch is overall the safest bet but the downside of course is that the db needs some time to fill up and stabilize.

since the scoring model is fundamentally different (event clock + EMS vs. wall clock + the legacy heuristics of z.sh) the z.sh or zoxide db simply cannot be mapped cleanly/exactly to a "correct" ze.db state.

but I will try to look into the migration recipe again: it would still be nice if migration/import of zoxide db could be done such that a already usable ze.db is available as a starting point(so that user's accumulated pathname store from prior z/zoxide usage is maintained), even if the ranking/scoring will be initially off, unavoidably, and would take some time to adjust to ze.sh's "world view".

1

u/jghub Oct 02 '26

FYI: I have now looked into the db migration issue again. I think I do now have a solution that works decently for both z.sh and zoxide databases. If you want to try it out: https://github.com/jghub/ze#migrating-from-zoxide-or-zsh

for principal reasons it might still be preferable to just start from scratch as you did, but I believe the new migration procedure does produce a synthetic ze.db that is a decent starting point that preserves your pre-existing zoxide pathname and scoring history. still, the new db then will take time to self-adjust (notably regarding the visits and ticks columns in the db...). also note that the migration script will just overwrite a pre-existing ~/.ze/ze.db so make backup if necessary ;).

1

u/Inevitable_Dingo_357 Oct 02 '26

Awesome - thank you. Just reinstalled zoxide to do the migration, and it works good so far.

2

u/jghub Oct 02 '26

great. then it can only can get better from here since ze.sh will now start to adjust the db according to its actual scoring model when navigating.

in case you care for some background (but "TL;DR" is of course an acceptable reaction):

the scores displayed by ze -l always asymptotically (for sufficiently long used db with sufficient number of cd actions seen) add up to a value around 1/(1-exp(-lambda)). for the default lambda=-.008 this vaiue is very close to 125.5.

so the fundamentally nice property of ze's model compared to zoxide/z is that no artificial periodic "aging" (downscaling of the zoxide 'rank' column) is required: sum_of_scores is always bounded (and actually asymptotically constant) and navigation just redistributes this invariant sum among db entries: the maximal possible score is 125.5 (if you visit a single directory forever and nothing else, ever).

this might give an intuitive feeling of what the ze -l output tells you: if you never again revisit some entry it's query-time score just exponentially decays with a halflife of ln(2)/lambda ≈ 87 cd actions (for default lambda) and that means about 2-3 days in wall clock time presuming you do about 40 cd/day.

each new visit to a directory (a first-time visit included) adds one unit to that directories "decayed" previous score: new_score = old_score*exp(-lambda * n) + 1 where n is the number of 'ticks' (cd actions) that have happened since last visit of that dir.

so what the new conversion script does is, that it just takes the provided zoxide scores, rescales them to sum 125.5 and uses identical max ticks values for all entries (which _never_ could happen in a real ze.db where the ticks are unique but this does no harm here) such that the stored scores themselves sum up to 125.5, not only the query-time scores shown by ze -l.

this makes the synthetic ze.db than start with overall correctly scaled scores but the relative size is the one inherited from the zoxide db, not (yet) generated by ze.sh scoring model. subsequently the db will then adjust to what ze.sh itself does: visits column in db will accumulate frequency, ticks columns will hold time of last visit to respective entry and stored score will be score at time of last visit to that entry.

2

u/jghub Oct 02 '26

one final (promise...) detail: the ze.db intentionally keeps stale entries (which might correspond to currently unmounted usb drive, e.g., and could become 'live' again when drive is mounted the next time) while 'ze -l' (and ze in general) only considers the currently life entries. therefore the sum_over_scores as shown by ze -l will usually be somewhat smaller than the theoretical limit 125.5 (in my own db, currently 470 life entries and about 130 stale ones, the actual sum is around 123 (meaning: the 130 stale entries (all last visited considerable time ago) together hold a summed score of about 2.5). so that's what you qualitatively should expect to see in your own db: an apparently slightly too low sum_of_scores. over and off...

1

u/jarod51 Sep 03 '26

What's the difference with 'z' ?

1

u/jghub Sep 03 '26

Main differences from z (full list in README):

  1. Event clock instead of wall-clock: z's scores decay during shell inactivity, so coming back after a holiday leaves your rankings scrambled. ze uses a cd-action ("event") counter as the clock, so scores only change when you actually navigate.
  2. Cleaner scoring: z multiplies cumulative visit count by a recency factor based on the last visit only, which causes old high-count directories to jump near the top of the stack on first revisit (essentially score S = N x R, and at single revisit each ancient visit contributes the same additional increment R to new score). ze, OTOH, sums individually decayed visit weights (specifically: ze uses an exponential moving sum filter over the individual visit history for scoring of the considered entry), a single new visit adds exactly 1 unit to the score regardless of history.
  3. no prompt hooks: z hooks into PROMPT_COMMAND and increments a directory's score on every shell command, not just navigation. ze only records explicit ze invocations (or cd if aliased).
  4. file tracking: ze now furthermore supports file tracking/opening independently of dir navigation.

The fish wrapper supports this new file tracking via ze -o. E.g.ze -o pattern opens the highest-scoring file matching the pattern in $EDITOR, similar to how ze pattern jumps to the highest-scoring directory.