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

Import from cd history #703

Open
moritz-t-w opened this issue Feb 16, 2024 · 5 comments
Open

Import from cd history #703

moritz-t-w opened this issue Feb 16, 2024 · 5 comments

Comments

@moritz-t-w
Copy link

I think it should at least be an option to train zoxide on the history of cd calls after installing it. I think it would even make sense to just do that by default.

@Pyrestone
Copy link

I built a simple python script that does this.

https://gist.github.com/Pyrestone/105c837f8aab14bd833d5807b2c43751

usage:

python zoxide_from_bash_history.py
#inspect the generated add_command.bash
bash ./add_command.bash

It certainly isn't perfect, and just tries to re-trace the history of cd in your .bash_history, to keep track of where you've been and how often.
If a path is absolute, it will just go there.
If it's relative, it will try to apply it to the last directory.
If that fails, will just try to apply it on top of your home directory to see if that works (unless it's "..", so "/home" doesn't become your most-visited directory).
Else, it will just ignore the path

In this way, it keeps track of all the places in your file system that you've likely been to, and on every change it saves it to a list of directories, which get added to a command which you can then run to add them all to your zoxide history at once.

@moritz-t-w
Copy link
Author

Wow you really went all the way down that rabbit hole and came back out with a result. I did not 😅

@Pyrestone
Copy link

TBH though, after doing that, I now hate that zoxide pollutes the bash_history with commands that are no longer valid normal cd commands. That's especially an issue when using "--cmd cd" in the zoxide init command.

Maybe I should make a feature request for a mode where zoxide replaces the entries it leaves in bash_history with the final cd command it actually executes in the end, so that the bash_history stays useful....

@moritz-t-w
Copy link
Author

That sounds like a good idea but I can imagine they wouldn't wanna do it because it's sorta nonstandard to manipulate the bash history, even if it's just an optional mode.

@NamkhangNLe
Copy link

This is really interesting.

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

3 participants