Sample Header Ad - 728x90

Piping continuous output into rofi

2 votes
1 answer
877 views
I'm trying to write a bash script to pipe strings into rofi. These strings are continuously generated by a function gen_x. The function gen_x sometimes (only when a condition is met) outputs new strings. I currently implement the gen_x-function with an if statement within an infinite loop. I want to pipe this function into rofi. When an item is selected within rofi, rofi should output the selected item and gen_x and rofi should end. When using an infinite loop which outputs a new element every loop (as seen in gen_b), the script does exactly what I described above. However, when I implement an if statement in my function and only print a new element when the condition is true, the program never ends. I am unsure if this is due to gen_x or rofi. Simplified code
gen_a(){ while true; do if [[ "$v" == "" ]]; then echo "Test"; v=1; fi; sleep 1; done }
gen_b(){ while true; do                             echo "Test";            sleep 1; done }

gen_a | rofi -dmenu # -> this outputs Test and does not end
gen_b | rofi -dmenu # -> this outputs Test and ends properly
Is there a way to use conditionals within the while-loop, and the program ending properly.
Asked by Friendly Penguin 123 (23 rep)
May 28, 2023, 05:26 PM
Last activity: May 28, 2023, 07:13 PM