ajeetdsouza / zoxide

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

Provide a way to configure where a bare `z` command goes #805

Closed pfmoore closed 2 months ago

pfmoore commented 2 months ago

When I start up a new shell, I have it configured to start in my "scratch" directory, C:\Work\Scratch. Because of this, I think of that directory as my "base location", and as a result it's where I would prefer the z command to take me by default. In contrast, my "home" directory is C:\Users\<myname> and is a place where applications store settings, configuration, etc - but it is not where I routinely store my files and/or projects.

It would be nice to have a way to set an alternative "default location". I guess the way to do this would be via an environment variable, say _ZO_DEFAULT_DIR.

To be clear, I would expect this to only affect the result when running z with no arguments. I don't want it to change the meaning of ~ (which is why I suggested _ZO_DEFAULT_DIR rather than _ZO_HOME).

ajeetdsouza commented 2 months ago

zoxide is designed for scriptability, you should be able to add a customization like this very easily. First initialize zoxide without a z command:

eval "$(zoxide init <your shell> --no-cmd)"

Then, you can write a custom function that handles the case with zero arguments, and calls __zoxide_z otherwise.