Skip to content

alternative/additional operation mode the simply completes the most recent directories #1116

@calestyo

Description

@calestyo

Hey.

Currently, AFAIU, zoxide stores all the dirs one changed to (via it) in some db and then selects/completes based on that.

It would be nice if one could additionally/alternatively (and make that configurable) have a mode where it presents the most recent current directories in order.
So roughly, e.g. if I do:

~$ z tmp
~/tmp$ z /etc
/etc$ z /tmp
/tmp$ z <see below>

it would use:

1: /etc
2: ~/tmp
3: ~

I'd kinda envision two ways to access this:

z -<n>

where <n> is number and -1 is the same as - (i.e. the previous directory), but -2 is the one before the previous and so on. Here the user would obviously need to know which one the -2nd was.

Or alternatively:

z -<TAB>

which would cause fzf to pop up and simply display the list from the previous, to the one before that and so on.

The whole idea is a simpler (but of course also more limited) but much faster mode than the current. If I know that I want to got to the nth previous dir, then typing -<n> is faster.

Also, sometimes I know that I've been to the right directory, a few cds before but don't really remember which one it was (and also don't have any good search string for it). The current mode doesn't help me that much now, but the one I propose here would give me simply the history of my most recent directories and I could look up, which I wanted.

For that reason, if doing the -<TAB> completion and getting the list in fzf, it might probably be useful, if fzf would then only show te most recent ones and no other possible candidates (or at least it should be configurable whether or not others should be included).

And as already said above, I think it would be good if one could configure which of the two modes one wants (both or either of them).

On top of that (as if it wouldn't already be enough 😇) ... it would be nice if one could configure whether the proposed mode works per shell or has a shared list of most recent dirs, over all shells.

Would be nice if one could set a global default for this (e.g. use a per-shell list per default), but could perhaps even change during the lifetime of a shell via some z --option from one to the other.

If per shell (which limits the list obviously to the lifetime of the shell) it would probably make sense to store the list in some ephemeral location (like /run/user/) - why causing disk writes if it's anyway only temporary? Storing the list in a shell variable would probably be tricky, as one would need a separator char (but then one needs a quoting system for that), unless of course one has e.g. arrays like with bash.

Maybe such an ephemeral per-shell (which means not shell type, but lifetime of a shell process) mode would even make sense for the current mode of z.

One could even imagine more like -<n> using the nth previous from either the per-shell store or the global user-wide one, depending on what the respective shell has set as its default (that was what I've proposed above).

Additionally -s<n> could always access the per-shell store and -g<n> could always access the global one.

One could further make it configurable what should happen with duplicates in the most recent directories list. Similar to what bash’s ´HISTCONTROL=ignoredups` does.
Like if doing:

cd 1
cd ~
cd 2
cd ~
cd 3
cd ~

Should the list be:

3
~
2
~
1

or should it only be:

3
~
2
1

with all earlier duplicates being removed from the list.

Thanks,
Chris.

PS: Question, when I do z foo and the current directory has a subdirectory foo, can it every happen that it doesn't change into that but e.g. into /some/other/foo?

I kinda inferred that from the documentation:

z foo              # cd into highest ranked directory matching foo
z foo/             # cd into relative path

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions