ajeetdsouza / zoxide

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

[Feature Request] Jumping to children of current working directory #459

Open leoshimo opened 2 years ago

leoshimo commented 2 years ago

Feature request to add additional shell commands for jumping to children for working directory, similar to jc in autojump.

WDYT about bringing this to zoxide?

Happy to take this task on.

ajeetdsouza commented 1 year ago

Sure! I'd suggest a feature that works this way:

You'd be able to use z . foo and it would only match a subdirectory.

Blonteractor commented 1 year ago

Got a working backend for this. Right now I added a zw command which cds into a subdirectory by passing the --workingdir flag to zoxide query.

Blonteractor commented 1 year ago

I got it working by making it a different command in the shell scripts, zw, don't know enough bash to implement checking the first parameter to zoxide query and triggering the respective behavior but it should be trivial, sound good?

ajeetdsouza commented 1 year ago

This behaviour should be triggered within Rust rather than within Bash, since it would be common to all 8 shells supported by zoxide.

Blonteractor commented 1 year ago

Aight made a pull request

mtalexan commented 7 months ago

I'd argue this should also be the default behavior for the z and zi commands, and a different command should be used for cases where the current directory context isn't relevant.

The z.lua tool (and for some cases z and autojump) seems to have understood that the following is the order for how common actions are:

  1. Going to sub folder of the current
  2. Going to the functional root (e.g. git root, hg root, etc) above the current
  3. Going to a parent directory by name match
  4. Going to an equivalent directory to the current, where some portion of the parent path is swapped for something else
  5. (not handled by them) A recent folder unrelated to the current one.

Option 5 already has a poor manual jump list in Linux with pushd, popd, dirs, ~1/, ~2/, etc.

Currently I would estimate 98% of use cases a jump command wants to do something relative to their current folder (up, down, or over). Only a small number of cases want to jump to unrelated folders. Unfortunately, Zoxide currently only supports jumping to unrelated folders, and custom functions would need to be written to enable jumping to folders relative to the current (e.g. a custom function that automatically inserts the current path as the first search term).