Hacker News new | ask | show | jobs
by jvanderbot 265 days 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.
1 comments

If I'm reading this correctly, this will pass all subdirectories to fzf, which is very different from only directories you've visited.
The 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.

`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.)
Yes, 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.
What 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).
How 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.