5 ms·
I tried this and a handful of alternatives a while back, but would often get frustrated because they’d jump to something different than what I intended or were
by latexr 3y ago
I tried this and a handful of alternatives a while back, but would often get frustrated because they’d jump to something different than what I intended or were missing some directory I wanted.
Eventually I came up with an alternative using fd¹ and fzf². I have a variant of this in my .zshrc:
function n {
cd "$(fd . "${HOME}" --type d --color never | fzf --select-1 --query "${*}")"
ls
}
Call it with `n` and get an interactive fuzzy search for your directories. If you do `n <argument>`, it’ll start the find with `<argument>` already filled in (and if there’s only one match, jump to it directly). The `ls` is optional but I find that I like having the contents visible as soon as I change directories.
In my personal setup I’m also including iCloud Drive while excluding the rest of the Library directory³ as that is too noisy. I have a separate `nl` function which searches just inside `~/Library` for when I need it, as well as other specialised `n<char>` functions that search inside specific places that I use frequently.
¹ https://github.com/sharkdp/fd https://github.com/sharkdp/fd
² https://github.com/junegunn/fzf https://github.com/junegunn/fzf
³ Change the fd command to: fd . "${HOME}" "${HOME}/Library/Mobile Documents/com~apple~CloudDocs" --exclude '/Library/' --type d --color never
- techwizrd 3y agoI was frustrated with jumping to frecent directories, so I "reverted" back to jumping back to bookmarked directories [0] (which I find much more predictable). 0: https://github.com/techwizrd/fishmarks https://github.com/techwizrd/fishmarks
- BeetleB 3y agoYes, I made a similar keybinding for xonsh, using fd and fzf. I press Alt-c, and fzf shows me all the subdirectories rooted where I'm at. That's a good intermediary solution. But the one that totally changed my flow was to combine autojump[1] and fzf. autojump is similar to Z (this submission). It stores all the directories you've visited in an SQLite DB and can show them to you (ordered by visit frequency) with a command line argument. So I pipe that to fzf. Now I can extremely quickly jump to any directory I've been to before - it really helps that they're sorted by visit frequency. I honestly use this more than any other approach - and I probably go for days on end without using the usual TAB autocompletion. [1] https://github.com/wting/autojump https://github.com/wting/autojump
- mixedmath 3y agoThis seems pretty great! I love tips like this. I'm going to try out a version of this now.
- Arcuru 3y agoIn most shells, you can just add those entries as shell completions to `cd` or `z`. In fish for example, it's as easy as the following (using zoxide query) complete -c z -f -k -a "(zoxide query -l)"
- latexr 3y agoI don’t just want specific directories to autocomplete. Whatever I navigate to is likely something I never even opened but was generated by a script and I now want to do manual changes to the contents. This approach makes for me the rare case as usable as the common one.
- keyle 3y agoHey thanks! I've been wanting something like this for ages, and didn't really think about combining fzf with fd. I've tweaked it to search a lot less folders (depth 5) and to restrict to a pattern beginning by X... cd "$(fd "^${*}" "${HOME}" --max-depth 4 --type d --color never | fzf --select-1 --query "${*}")" This makes it super snappy. I probably have waaay too many folders with similar names.
- agumonkey 3y agoSame reflex. As much as I appreciate full depth, I realize I really have many deep trees and it makes things laggy. ps: out of fun, I wanted to toy with fzf --multi mode function zzg { local selection="$(fd . "${HOME}" --type d --color never --max-depth 4 | fzf -m --query "${*}")"; local term="xterm" for dir in $selection do "${term}" -title "zzg({$dir})" -e "cd ${dir} && bash" & done }