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

Using selecta multiple times in one pipeline doesn't work #70

Closed decklin closed 9 years ago

decklin commented 9 years ago

I'd like to wire up more than one selecta in a pipeline. Here's a contrived example:

$ cat findword
#!/bin/sh
read letter && grep "^$letter" /usr/share/dict/words
$ printf '%s\n' a b c d e | selecta | ./findword | selecta

So, I would use the first selecta to pick a letter, then output that to another script which generates more choices, and use the second selecta to pick a word from those. (In reality, these would be network queries or something else non-trivial.)

The first selecta works normally, but the second one does not. The list of choices doesn't update until I press enter, and then pressing enter repeatedly causes the cursor to quickly jump to the highlighted word and back to the input line, without exiting. I can press ^C to exit without any output, but that's it.

I'm guessing this has to do with how the TTY is reopened after stdin/stdout have already been redirected by the pipeline, but I don't know enough about how that works.

garybernhardt commented 9 years ago

Ahh, I never thought of that! As soon as I read your description, I knew what was happening. I'd just never bothered to try multiple selectas in a pipeline. Give master a try and I bet it'll work. (If you're not running selecta from master currently, you can just check it out and run the selecta script directly without setting anything up.)

decklin commented 9 years ago

Awesome, it works now. Thanks!

garybernhardt commented 9 years ago

No problem, thanks for the clear report. :)