pazz / alot

Terminal-based Mail User Agent
GNU General Public License v3.0
696 stars 164 forks source link

fzf in addressbook shell command #1550

Closed ndaman closed 3 years ago

ndaman commented 3 years ago

This is maybe more of a help request or misunderstanding than a feature request or bug report, but it might end up being one or the other, since I don't know what is causing my issue.

I have set up address book completion using shell commands (notmuch address --format=json) per the excellent documentation.

The completion is only so-so for me, however, and I would like to combine it with fzf. From the command line, this does exactly what I want:

notmuch address --format=json %s | fzf

But this does not work from alot if I type that command directly, is there a different way I need to type the command to deal with some kind of escaping going on or is this not possible to execute from inside alot?

pazz commented 3 years ago

Hi and welcome to alot!

I am not sure but it seems that pipes are not picked up immediately by alot's command line (and underlying shell cmd call) and may need escaping. Have you checked the debug log for any indication? (alot -l logfile -d debug)

One hotfix for you would be to put your commands into a dummy shell script, and call that from within alot.. HTH, P

Quoting ndaman (2020-11-04 22:29:20)

This is maybe more of a help request or misunderstanding than a feature request or bug report, but it might end up being one or the other, since I don't know what is causing my issue.

I have set up address book completion using shell commands (notmuch address --format=json) per the excellent documentation.

The completion is only so-so for me, however, and I would like to combine it with fzf. From the command line, this does exactly what I want:

notmuch address --format=json %s | fzf

But this does not work from alot if I type that command directly, is there a different way I need to type the command to deal with some kind of escaping going on or is this not possible to execute from inside alot?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.*

ndaman commented 3 years ago

Thanks for the quick feedback (and thanks for your work on alot!)

Nothing seems to be amiss when looking at the debug log file:

DEBUG:helper:Calling ['notmuch', 'address', '--format=json', '%s', '|', 'fzf', 'ndama']
DEBUG:external:Apply \[?{"name": "(?P<name>.*)", "address": "(?P<email>.+)", "name-addr": ".*"}[,\]]? on 1 results

After a little fiddling, the shell command works! The challenge (which might not be easy to overcome) is that fzf's fuzzy finding list does not appear while typing, and the usage ends up being a little bit counterintuitive, I need to press tab before typing the name, type a name and press enter, hoping that the correct address has been matched. Is there any way to show a floating window while typing?

For my use case, it may be better/easier to implement this from (neo)vim as an fzf#run function, but I'm having trouble getting the '%s' to translate properly.

pazz commented 3 years ago

After a little fiddling, the shell command works!

I'm actually surprised by this, because I did not expect the underlying hellper, via subprocess to interpret pipes.. but good :)

Is there any way to show a floating window while typing?

I'm afraid not at the moment: Alot's prompt is actually an urwid text widget that will call a complete function, in this case alot.completion.abooks.AbooksCompleter.complete, every time you hit the tab key.

I'm sure that this could be extended so that every time you hit any key, the current text content is filtered but there has not been a use case so far.