agkozak/zsh-z

Feature: "zsh-z --add" should be exposed via -h / --help

zachriggle opened this issue · 5 comments

I have a HUGE (200+) set of Git repositories that I regularly jump between. Occasionally, I'll clone something, but not cd into it, so it isn't visible to zsh-z. This is kind of annoying, since then I have to find it manually.

Desired Goal

I would like to be able to do something like this:

find $PWD -maxdepth 3 -name .git -type d \
    | xargs dirname \
    | sort \
    | while read dir; do 
        echo $dir
        z -a $dir
    done

To add all of the directories which contain a .git directory in them, to the zsh-z database. Simply doing a cd $dir is insufficient, since zsh-z populates on one of the prompt-hooks (not sure if it's pre- or post-) which is not executed.

Further Investigation Yields Results

It looks like I might be able to manually invoke _zshz_add_or_remove_path, and looking at the source for _zshz_precmd it looks like it makes use of zshz --add "$dir" -- so perhaps this functionality is already present, but is not exposed via z --help?

This does seem to work in practice! (Yay!)

$ randpass
sCBMyTuAJ6oDzL3S4iZjDQ==

$ mkdir sCBMyTuAJ6oDzL3S4iZjDQ==

$ z --add sCBMyTuAJ6oDzL3S4iZjDQ==

$ z 3S4i

$ pwd
/Users/zachriggle/sCBMyTuAJ6oDzL3S4iZjDQ==

Closing Remarks

It looks like this functionality is already implemented, but is not exposed via -h / --help. Might be useful to add it.

Thanks in advance!

Thanks so much for the suggestion and for providing your use case. I'll address this matter within the next few days.

Friendly 🛎️❤️

Thanks, @zachriggle. I think if I'm going to suggest --add as a feature for the general user, I may want to alter its behavior so that it can handle a relative path; right now it expects a full path. Would you agree? I'm trying to think if there is any way that could backfire.

OK, this has been merged to master. Many thanks as always!