aperezdc / zsh-fzy

Use the fzy fuzzy-finder in Zsh
MIT License
55 stars 9 forks source link

Use manually typed prefix for file widget as starting point of the search #15

Open maximbaz opened 5 years ago

maximbaz commented 5 years ago

Pressing Ctrl+T now searches starting from the current directory.

Sometimes I'd like to type a prefix and then press Ctrl+T to search from there. Suppose I'm in ~/work/project/vendor/ and I want to move here a file from ~/Downloads, I imagine typing mv ~/Downloads/ and pressing Ctrl+T to start the search.

The paths could be relative, i.e. if my vendor folder is huge and I just want to find a file of specific library, I type vim lib/ and press Ctrl+T to search starting from ~/work/project/vendor/lib/.

To handle cases like vim ~/Down<Ctrl+T> we could say that starting dir is the last typed WORD until the last slash, which in this case is ~/.

aperezdc commented 5 years ago

This seems easy on the surface, but after a quick try today I noticed that it involves parsing $LBUFFER to figure out which one is the current argument, and go from there. I would rather not implement our own shell syntax parser, so I'll have to check and see if there is something already being provided by Zsh — probably yes, because the completion definitions are likely to need and use such a functionality.

Edit: Maybe split-shell-arguments (from the Utility functions section of the manual) would do here. It looks somewhat cumbersome to use :upside_down_face:

maximbaz commented 5 years ago

Just to add, I'm pretty sure this functionality is implemented in fzf one way or another, but I can't test now to verify (sources are here and here).

I think it doesn't have to be fancy, so if there's no suitable built-in solution, we can make a very simple detection rule: take the last word and check if it is a dir, if not, cut the word until the last occurrence of / and try again.