aperezdc / zsh-fzy

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

Show fzy under prompt, not on top of it #12

Closed maximbaz closed 5 years ago

maximbaz commented 5 years ago

It would be very useful to show fzy under prompt, so the currently typed command remains visible.

Let's say you want to open two files at once in vim. Because fzy lacks multiselect, the only available way is to trigger zsh-fzy multiple times. With #11 I sneaked in a little patch that allows to do so with just pressing Ctrl+T instead of <Space>Ctrl+T, but because you can't see the prompt you can easily forget which files you've already selected and which not.

Same applies for proc widget, if you want to kill multiple processes at once, you want to see your kill command build up, select first process, see that your kill became kill 1234, select second process, see that your command expanded to kill 1234 5678, etc.

I didn't find yet how fzf achieves this, do you have a hint for me maybe?

I even think this behavior should replace the current behavior, i.e. I wouldn't add a configuration option to return the current approach where fzy overlays prompt. But if you deliberately wanted this, then of course I'm happy to make it configurable.

maximbaz commented 5 years ago

Nice! 🎉

aperezdc commented 5 years ago

Great suggestion! I didn't really know how to do this, but while thinking how nice this would be in order to make fzy behave like the Zsh completion menus, which also appear under the prompt, it crossed my mind that there's probably something in Zsh that can do the “print below the prompt, go back to the prompt afterwards” routine. And there is a way:

function some-widget {
    zle -M 'some string'
    # Now call fzy, do things.
    zle redisplay
}

Adding the above to a widget function will make Zle save the prompt position, print some string below the prompt, which causes the terminal cursor to go down one line, and the redisplay will go back and repaint the prompt in the saved position. Because the cursor went down one line, invoking fzy now overwrites some string instead of the prompt.

maximbaz commented 5 years ago

Genius idea, I couldn't think how to even start approaching this, turns out it's very simple 🙂

Rebased #11 on master, so the proc widget also appears under the prompt now.