fix some warnings if searchdirs are missing

This commit is contained in:
Tilman Kranz 2024-11-14 05:03:01 +01:00
parent f7f760cba9
commit 0eb7823f56

View File

@ -6,13 +6,12 @@
##
# Configuration
name=$(basename "$(readlink -f "$0")")
IFS=":"
xdg_data_dirs=${XDG_DATA_DIRS:-/usr/share/gnome:$HOME/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share}
search_regex=.*
search_regex=".*"
help=false
verbose=false
show_directives_regex=.*
show_directives_regex=".*"
search_directives_regex="(Name|Exec)"
##
@ -162,9 +161,9 @@ parse_options() {
esac
done
[[ "${#search_directives[@]}" -gt 0 ]] && search_directives_regex="($(join "|" ${search_directives[@]}))"
[[ "${#show_directives[@]}" -gt 0 ]] && show_directives_regex="^($(join "|" ${show_directives[@]}))="
[[ "${#search[@]}" -gt 0 ]] && search_regex="^$search_directives_regex=.*($(join "|" ${search[@]}))"
[[ "${#search_directives[@]}" -gt 0 ]] && search_directives_regex="($(join "|" "${search_directives[@]}"))"
[[ "${#show_directives[@]}" -gt 0 ]] && show_directives_regex="^($(join "|" "${show_directives[@]}"))="
[[ "${#search[@]}" -gt 0 ]] && search_regex="^$search_directives_regex=.*($(join "|" "${search[@]}"))"
}
valid_data_dirs() {
@ -173,7 +172,7 @@ valid_data_dirs() {
local result=()
for dir in $dirs ; do
if [[ -d $dir ]] && [[ -r $dir ]] ; then
if [[ -d $dir/applications ]] && [[ -r $dir/applications ]] ; then
result+=( "$dir" )
fi
done
@ -184,18 +183,18 @@ valid_data_dirs() {
##
# Main Program
parse_options $@
parse_options "$@"
"$help" && { usage ; exit 0 ; }
found=0
for _data_dir in valid_data_dirs "$xdg_data_dirs" ; do
for _data_dir in $(valid_data_dirs "$xdg_data_dirs") ; do
data_dir=$(realpath --canonicalize-missing --no-symlinks "$_data_dir")
applications="$data_dir/applications"
[[ -d $applications ]] && for desktop in "$applications"/*.desktop ; do
grep -Eiq "$search_regex" "$desktop" && {
grep -Eiqs "$search_regex" "$desktop" && {
(( found++ ))
if "$verbose" ; then
echo "# $desktop"