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

Usage with multiple directories that have an identical shape #528

Closed
thenbe opened this issue Jan 27, 2023 · 2 comments
Closed

Usage with multiple directories that have an identical shape #528

thenbe opened this issue Jan 27, 2023 · 2 comments

Comments

@thenbe
Copy link

thenbe commented Jan 27, 2023

Note: I'm new to zoxide and also recently found out about git worktrees.

Using zoxide with git worktrees is great. Being able to do z <branch-name> and instantly cd into that worktree feels super clean.

Moving to a worktree

~ $: z feature-branch
~/feature-branch $:
# Great, we're in the feature-branch worktree as we intended.

Moving within a worktree

That being said, I'm still having trouble when it comes to cd'ing into directories within a given worktree.

1. From worktree root

Consider the case where you're in your feature-branch worktree, and want to jump into it's test directory. This is more challenging, as illustrated below:

~/feature-branch $: z test
~/master/test $:
# not what we usually want- we're taken to the test directory in the master worktree

Unlike what we intended, we're almost always taken to the test directory in the master worktree because it almost always has a higher ranking than any newly created worktree. This could be solved by #468.

2. From any subdirectory in a worktree (not necessarily it's root)

~/feature-branch/test $: z src
~/master/src $:
# not what we usually want- we're taken to the `src` directory in the master worktree also because of it's higher score

Unlike the example above, this use case is not in scope for #468. Some possible areas to explore for a solution:

  • _ZO_EXCLUDE_DIRS. Perhaps we can use this to exclude other worktrees if we are in one.
  • ?

I'm still not sure what's the best approach to take here. Ideally, the solution would look something like:

When we are in any worktree, we want zoxide to rank it higher than any of it's counterparts.

Any advice for a good approach to tackle this issue? I'm aware that this issue has multiple solutions- most of which possibly lie outside zoxide's scope. I'm just looking to be pointed in the right direction as I'm not sure which layer the logic should be inserted at.

I'm also curious about any general ideas or solutions other folks have implemented when dealing with multiple directories that tend to have a very similar shape, git worktrees or otherwise.

Workaround:

Currently, this is what I use:

  1. Use zoxide to cd into a worktree
  2. Use fzf's Alt+c to fuzzyfind+cd into any of it's subdirectories. This guarantees that only the subdirectories of the current pwd are in scope for the fuzzy search.
@thenbe
Copy link
Author

thenbe commented Aug 5, 2023

I've created a small utility that may help others with a similar worflow: worktree-welder

@thenbe
Copy link
Author

thenbe commented Dec 1, 2023

I've settled on a workflow that solves this. Write-up here.

@thenbe thenbe closed this as completed Dec 1, 2023
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

1 participant