garybernhardt / selecta

A fuzzy text selector for files and anything else you need to select. Use it from vim, from the command line, or anywhere you can run a shell command.
MIT License
1.34k stars 81 forks source link

Just redirect stdin to stdout if zero or one lines #62

Closed untitaker closed 9 years ago

untitaker commented 9 years ago

In neither case the user would have a choice to do anything else than make selecta re-print the same line to stdout.

garybernhardt commented 9 years ago

Always showing the UI ensures that users see consistent behavior they can rely on. For example, when Selecta is part of a big shell command, there might be a delay before it's actually run. You can confidently type a query and it'll be queued in the TTY's buffer until Selecta shows up to consume it. Making the UI conditional would make users wait until the UI shows up before they start typing.

untitaker commented 9 years ago

Good point. Would you be opposed to make such behavior optional?

garybernhardt commented 9 years ago

Yes: options are complexity and maintenance cost that sticks around forever. You can always write a wrapper function or script to examine stdin and only run selecta if it's non-empty, though.=

untitaker commented 9 years ago

Hmm, i think my original proposal was too vague and didn't cover all cases where selecta's current behavior was an annoyance to me. I can't write a wrapper script for the case where there would be only one result when selecta is called with the -s option. For example:

echo -e"1\n2\n3" | selecta -s 3

I can't see a way to write a wrapper script around selecta without basically re-implementing its matching algorithm.

untitaker commented 9 years ago

Perhaps this problem could be solved by introducing an option for non-interactive usage instead? I suppose such a feature would be more broadly useful, and can help me with the implementation of my own wished behavior.

garybernhardt commented 9 years ago

In theory, I'm not opposed to exposing the ranking algorithm for use by other tools. However, that's a lot of maintenance and compatibility burden to take on. For example, every tweak of the algorithm will then potentially change the behavior of downstream tools, which is bad. Can you explain what you're trying to use Selecta for so I understand the situation better?

untitaker commented 9 years ago

Going into full detail:

Originally i wanted to modify mutt's query_command with something that would call selecta. This failed miserably because the result is a glitchy mixture of mutt's and selecta's UIs. So I wanted to write a simple shell script called m instead, which would simply launch selecta with all my contacts fed, let me select one and start email composition in mutt with the selected address. This worked just fine. Then I wanted that script to pass any further arguments to selecta's -s option. I expected to be able to write m somebody, and it would launch mutt with the only match.

Instead I noticed that it opened selecta with the only match before, so naturally I opened this issue and had this discussion with you. I then tried to write a wrapper around selecta for the behavior I wanted, but as discussed, there is currently no way to determine the number of matches selecta would find with the given search query.

Maybe the glitchy behavior around mutt would be a separate issue worth investigating.