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

Feature: Prefer directories which contain a .git directory, if query matches repo directory name #38

Open
zachriggle opened this issue Mar 11, 2021 · 1 comment

Comments

@zachriggle
Copy link

zachriggle commented Mar 11, 2021

I use zsh-z primarily to jump between various directories that are tracked as git repositories.

Occasionally, there will be a higher-'frecency' match that is a subpath of some repository, when I really want to change to a repository that matches the query.

It would be nice if zsh-z had an optional flag to prioritize directories which contain a .git directory. This could be done at scoring time, or at invocation-time (i.e. of all matches for query QUERY, take the first one that has a .git directory, if the directory name itself matches QUERY, otherwise the most 'frecent' directory). This would only take effect if the query were a match for the name of the repository itself, so that e.g. z somedir doesn't drop me at the root of the repository, but would behave as it does not normally.

TL;DR An environment variable that prioritizes git repository roots if the search query matches the directory name containing a git repository (but queries for subpaths that do not match the repo name are unchanged).

Examples

I want to change to the git repository that has 'iob' in the name. I recently spent some time in a completely unrelated directory that has 'iob' somewhere run its subpath, and it is now ranked higher. This is undesirable for my use case.

Current behavior

~ ❯❯❯ z iob
~/s/C/m/m/IOBxxx/P/somedir ❯❯❯

Desired behavior

~ ❯❯❯ z iob
~/s/C/iobXYZ ❯❯❯ ls -d .git
.git
@zachriggle zachriggle changed the title Feature: Heavier weighting for directories which contain a .git directory Feature: Prefer directories which contain a .git directory, if query matches repo name Mar 11, 2021
@zachriggle zachriggle changed the title Feature: Prefer directories which contain a .git directory, if query matches repo name Feature: Prefer directories which contain a .git directory, if query matches repo directory name Mar 11, 2021
@agkozak
Copy link
Owner

agkozak commented Mar 12, 2021

Your idea is a clever one. I’ll play around with it a bit.

In the meantime, I think you might be able to accomplish what you want by using the setting

ZSHZ_UNCOMMON=1

It’s an alternative way of deciding which directory to switch to. If you run

z bar

and the best match is /foo/bar/bat, you’ll end up in /foo/bar because you searched for bar. If you’d run z foo and the best match was /foo/bar/bat, you’d end up in /foo.

That’s the setting I use myself. See if it helps.

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

2 participants