I'm writing a bash script that is a "package manager" that uses pi-apps.
I want to implement a search function so I can search apps.
right now what I'm doing is this (template is a folder I don't wan't it to list):
#test-search.sh
PI_APPS_DIR="$HOME/pi-apps"
function list-all() {
for dir in $PI_APPS_DIR/apps/*/; do
dirname=$(basename "$dir")
if [[ "$dirname" != "template" ]]; then
echo -e "\n${bold}${inverted}${light_blue}$dirname${normal}"
DESC="${green}$(cat "$dir"/description)${normal}"
echo -e $DESC
fi
done
}
function search() {
for dir in $PI_APPS_DIR/apps/*/; do
dirname=$(basename "$dir")
if [[ "$dirname" != "template" ]]; then
echo "$dirname" | grep "$1"
fi
done
}
# the function is then called like this
if [[ "$1" == "search" ]]; then
#search a app
FIND="$(search "$2")"
list-all | grep "$FIND"
fi
and run it like this: ./test-search.sh search "APP" (app being the search term).
what happens is this: if the searh term is in the name of a app and its description, I get something like this:
./test-search.sh search "Q"
QEMU
description.......
but if I use q, it will just list all the apps.
and if the search term is only in the description of the app, only the description gets printed.
the file tree looks like this:
~/pi-apps/apps
inside apps there is a folder for each app named the name of the app, Zoom for example.
there is 1 folder called template that I don't want to list.
here is the same project by someone else but written in python: https://github.com/techcoder20/PiAppsTerminalAdvanced/blob/main/PiAppsTerminalAdvanced.py I think it helps to understand what I want to do.
catfor the description) so the output is similar to the one ofapt searchsearchreturns the empty string, you then calllist-alland grep for the empty string. Therefore, everything is listed.