3 ms·
You 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 comp
by jvanderbot 1y ago
You 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 agoYes, the marginal improvements from changing your entire shell are not to be disregarded. I'll change to asserting that it's entirely possible to do a nice 80/20 without changing shells.
- robenkleene 1y agoWhat do you mean? Zoxide isn't a shell, it's just a CLI program. It doesn't involve changing shells, you can see the list of supported shells in the README (it's more comparable to fzf than a shell, it ships with optional shell integrations the same way fzf does).
- jvanderbot 1y agoHow did you get all the way down here and lose the fact that top level comment is about zsh and finding past commands, and also changing directories? Was it not you that brought up zsh? And I that brought up bash examples to show how it might be done? We've gone around in circles lads back on the bus.
- BeetleB 1y agoHe never said he changed shells - just that he uses zsh history. He was likely using zsh anyway.
- jvanderbot 1y agoMy logic (take it or leave it) is that since zsh is not the default distro nearly anywhere (Kali?), a randomly selected person who might read that advice (and subsequent advice ITT), would likely find "Use ZSH" includes a shell change and therefore more learning curve than "add a few lines to .bashrc". This is getting off topic, pedantic, and (maybe?) argumentative so I'm calling it quits. Cheers.
- BeetleB 1y ago