ajeetdsouza / zoxide

A smarter cd command. Supports all major shells.
MIT License
22.55k stars 548 forks source link

Usage with multiple directories that have an identical shape #528

Closed thenbe closed 11 months ago

thenbe commented 1 year ago

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:

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 commented 1 year ago

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

thenbe commented 11 months ago

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