Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

z history is pruned if a filesystem is not mounted #307

Open
systemmonkey42 opened this issue Sep 6, 2021 · 3 comments
Open

z history is pruned if a filesystem is not mounted #307

systemmonkey42 opened this issue Sep 6, 2021 · 3 comments

Comments

@systemmonkey42
Copy link

Issue: If I use z when a filesystem (like /home) is unmounted, all references to /home are instantly purged from the cd history.

This has caught me out enough times ( I have a 100TB zfs pool I unmount for maintenance occasionally ) that I use a patched z which tracks the mountpoint.

Missing paths are filtered as normal when deciding where to go, but paths are only deleted if they are missing AND the mountpoint is actually mounted.

@systemmonkey42 systemmonkey42 changed the title z history is prunes if a filesystem is not mounted z history is pruned if a filesystem is not mounted Sep 6, 2021
@rupa
Copy link
Owner

rupa commented Sep 9, 2021

not opposed to a way to deal with this, but not 100 sure how I'd go about it. If you want to share your patch maybe I'll get inspired :) (or a PR if your implementation is tidy)

@systemmonkey42
Copy link
Author

Hi

Unfortunately my code isn't a "patch" to your code, but more of a reimplementation "inspired" by z which suits my needs.

The mountpoint stuff is also linux specific in that it reads /proc/self/mounts rather than parsing the output of df, but I'm pretty sure they are very similar (make sure you use the -P flag on df if it is supported on the platform you are using.)

The logic was simple:

  • When "adding", check the mountpoint a path is under, and save that as a column
    • eg, /home/user/work/project/test -> saved as /home|/home/usr/work/project/test|...
  • When scanning the z history file, get awk to pre-load the list of mountpoints
    • eg. awk 'BEGIN{while("df -P" | getline ) { mount[$NF]=1 }}{...}'
    • When the first field (mountpoint) isnt in 'mounts', ignore it when picking a directory to go to, and avoid pruning it when adding (but age it out, in case it never comes back).

Regards

@agkozak
Copy link

agkozak commented Sep 16, 2021

My ZSH-z plugin accomplishes this by having a ZSHZ_KEEP_DIRS array of directories that should never be removed and whose subdirectories should never be removed. Something similar could be done in the _z_dirs function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants