4 ms·
I like using fzf combined with zsh's shell history filtering. You can type `cd ~` and press CTRL+r to immediately fuzzy match commands you've run with `cd ~`.
by nickjj 1y ago
I like using fzf combined with zsh's shell history filtering.
You can type `cd ~` and press CTRL+r to immediately fuzzy match commands you've run with `cd ~`. fzf naturally ranks paths to cd into on top. If you find that too noisy you can just hit CTRL+r with an empty prompt and then search for `^cd ~` to only find cd commands.
I've written about filtering related history with zsh here: https://nickjanetakis.com/blog/hooking-up-fzf-with-zsh-tab-complete-and-filtering-related-history https://nickjanetakis.com/blog/hooking-up-fzf-with-zsh-tab-c...
If you want to go into ultra lazy mode you can also type `cd ` and spam the up / down arrows to only show commands from your history where you cd'd into a directory. That use case is also covered in the above post. I normally don't use this for changing directories but it can be done.
- robenkleene 1y agoYeah the problem with this approach to me is populating the history with a bunch of cd to absolute paths to begin with, which is not something I'd do natural (I have many ways I'm navigating the file system), and definitely wouldn't do manually. Not having to populate that list is the advantage of zoxide.
- jvanderbot 1y agoFrom 2024 when this was last posted: It appears to me that these could all be just tab complete, fzf, or similar. Some are just plain old bash. The commands are written in rust, presumably because they're part of this warp shell advertised on readme? I used to use this https://github.com/jodavaho/smartcd https://github.com/jodavaho/smartcd 'scd journal' 'scd logs personal' Now I tab complete using fzf, but the above is what you want. Bash is Turing complete. You "need" nothing else. You may want it for various reasons.
- robenkleene 1y ago- Recursive directory tab completion isn't viable for many key use cases (it'll hang with both monorepos and networked volumes). The only thing that makes zoxide viable is that it only matches against visited directories. (Similarly fzf doesn't have much of a relation here besides encouraging recursive fuzzy matching, which I tend to avoid because it doesn't scale to complex directory structures.) - Zoxide is probably sponsored by Warp, I doubt they have a relation beyond that, I'm not sure but they don't have much of a synergy beyond both being written in Rust. (The main point of relevance here is Warp is venture funded.) - Zoxide having a database outside of the shell is actually a huge advantage to me, because it makes it easy to access your database outside of the shell (e.g., Zoxide integration in Vim).
- nickjj 1y agoI think that's ok if you have absolute paths mixed in. If I have some long path like ~/src/open-source/dotfiles or /home/nick/src/open-source/dotfiles it all works with fuzzy matching. You can hit CTRL+r and then search for "cd dotfiles" and it finds it. The ~ isn't necessary, you can also do "^cd dotfiles"` for a tighter list of matches for paths that are more ambigious with other non-cd commands.
- jvanderbot 1y agoYou don't even need history. Just `find . -type d | fzf` to determine what dir to change to (or ~ for "anywhere else") 1. Make an alias fcd 2. Make a tab complete that does that for the command fcd This is kind of 101 bash - just DIY. Here's mine: (2) is the hardest part - just write something that works with `complete` and fzf. Nowadays this is childs play for any AI to just spit out. fz_comp() { COMPREPLY=() local cur="${COMP_WORDS[COMP_CWORD]}" local prev="${COMP_WORDS[COMP_CWORD-1]}" local opts="none" if [ -z "$cur" ];then COMPREPLY=($(find $1 -type d | fzf --preview="ls {} -l")) return fi COMPREPLY=($(find $1 -type d | grep $cur | fzf --preview="ls {} -l")) } (1) is just a) set the new command b) make the completion call c) map that call to <TAB> completion. alias fcd=cd _fcd(){ fz_comp $(pwd) } complete -F _fcd fcd there you go.
- BeetleB 1y agoIf I'm reading this correctly, this will pass all subdirectories to fzf, which is very different from only directories you've visited.
- jvanderbot 1y agoThe premise is the same: Dump history into fzf and add a grep/awk. My point was that requiring a new shell (or even history) is a limiting factor here, and either backwards search over commands (as suggested ITT), or just plan fzf directory changes are more functional and already integrated into bash.
- robenkleene 1y ago`cd foo` is useless in history if you're not already in foo's parent directory. This is the problem Zoxide solves, `z foo` will still do something useful in that case. (Side note about fzf, recursively fuzzy finding subdirectories fine for some use cases, but it doesn't scale as well as Zoxide.)
- jvanderbot 1y ago
- BeetleB 1y agoIt's (likely) simpler with zoxide + fzf. I use autojump, which is a lot like zoxide (possible predates it). It stores all the directories you've visited in an SQLite DB (along with the rank for each). I wrote a shell keybinding that presents me with fzf, along with the directories I've visited, in rank order. With just a few keystrokes, I can visit any directory I've ever visited, really fast. It doesn't need to be the top ranking directory for my query. I can't live without it now.