Is it possible to use gum filter through sh? gum filter is an interactive input filter similar to fzf. It reads a list of options on standard input, lets the user choose one or more options with fuzzy search, then writes the options the user chose to standard output. This means you must first feed it the input then let the user interact. On Linux it opens /dev/tty for input and displays the search TUI through standard error, leaving standard output for the result.
Here is how you can run it with subprocess.run in recent Python:
Can you do this with sh? The following code lets the user interact with the TUI and captures the output but does not provide an input.
import sh
import sys
print(sh.gum("filter", _in=sys.stdin, _err=sys.stderr))
I know there are Python-based alternatives to gum filter. (For example, there is pzp.) I am asking because I am curious if it can be done. I encountered this issue when porting a shell script that used gum filter to Python.
Is it possible to use
gum filter
through sh?gum filter
is an interactive input filter similar to fzf. It reads a list of options on standard input, lets the user choose one or more options with fuzzy search, then writes the options the user chose to standard output. This means you must first feed it the input then let the user interact. On Linux it opens/dev/tty
for input and displays the search TUI through standard error, leaving standard output for the result.Here is how you can run it with
subprocess.run
in recent Python:Can you do this with sh? The following code lets the user interact with the TUI and captures the output but does not provide an input.
I know there are Python-based alternatives to
gum filter
. (For example, there is pzp.) I am asking because I am curious if it can be done. I encountered this issue when porting a shell script that usedgum filter
to Python.