I am writing a script that searches the system for files and then for each file does some sanity checks, and if they pass those, I want to display them in fzf. When the item is clicked on in fzf, I want to run the file with a program.
So far I have:
dir="/path/to/dir"
fd . $dir --size +1MB | while read -r line; do
file_type=$(file -b "$line")
echo "$line" | fzf
if [[ "$file_type" == "data" ]]; then
echo "$file_type"
fi
done
Basically, I search for files bigger than 1MB in the specified dir. For each file I run the file command and check if the command output returns "data". If it does, I want to add it to the fzf list.
Then, when I click on the item, I want to run the file with the full path with an app: e.g.
myapp /path/to/file/selected/in/fzf
.
The problem so far is that fzf is blocking, and I can't populate the list in the loop. Do I really have to add everything to an array first and then pipe this into fzf? Ideally that should happen in parallel, aka, I want to add new items on the fly while the search is still going, instead of waiting for it to complete.
Also I dont know how to later run the selected file.
Can someone help me with this?
Asked by Kyu96
(193 rep)
Sep 21, 2021, 06:15 PM
Last activity: Dec 28, 2023, 09:12 AM
Last activity: Dec 28, 2023, 09:12 AM