Compare commits

...

2 Commits

Author SHA1 Message Date
Tilman Kranz
0eb7823f56 fix some warnings if searchdirs are missing 2024-11-14 05:03:01 +01:00
f7f760cba9 Update xdg-desktop-search 2024-11-14 04:57:31 +01:00

View File

@ -6,13 +6,12 @@
## ##
# Configuration # Configuration
name=$(basename "$(readlink -f "$0")")
IFS=":" 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} 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 help=false
verbose=false verbose=false
show_directives_regex=.* show_directives_regex=".*"
search_directives_regex="(Name|Exec)" search_directives_regex="(Name|Exec)"
## ##
@ -162,26 +161,40 @@ parse_options() {
esac esac
done done
[[ "${#search_directives[@]}" -gt 0 ]] && search_directives_regex="($(join "|" ${search_directives[@]}))" [[ "${#search_directives[@]}" -gt 0 ]] && search_directives_regex="($(join "|" "${search_directives[@]}"))"
[[ "${#show_directives[@]}" -gt 0 ]] && show_directives_regex="^($(join "|" ${show_directives[@]}))=" [[ "${#show_directives[@]}" -gt 0 ]] && show_directives_regex="^($(join "|" "${show_directives[@]}"))="
[[ "${#search[@]}" -gt 0 ]] && search_regex="^$search_directives_regex=.*($(join "|" ${search[@]}))" [[ "${#search[@]}" -gt 0 ]] && search_regex="^$search_directives_regex=.*($(join "|" "${search[@]}"))"
}
valid_data_dirs() {
local dirs=$1
local IFS=:
local result=()
for dir in $dirs ; do
if [[ -d $dir/applications ]] && [[ -r $dir/applications ]] ; then
result+=( "$dir" )
fi
done
echo "${result[*]}"
} }
## ##
# Main Program # Main Program
parse_options $@ parse_options "$@"
"$help" && { usage ; exit 0 ; } "$help" && { usage ; exit 0 ; }
found=0 found=0
for _data_dir in $xdg_data_dirs ; do for _data_dir in $(valid_data_dirs "$xdg_data_dirs") ; do
data_dir=$(realpath --canonicalize-missing --no-symlinks "$_data_dir") data_dir=$(realpath --canonicalize-missing --no-symlinks "$_data_dir")
applications="$data_dir/applications" applications="$data_dir/applications"
[[ -d $applications ]] && for desktop in "$applications"/*.desktop ; do [[ -d $applications ]] && for desktop in "$applications"/*.desktop ; do
grep -Eiq "$search_regex" "$desktop" && { grep -Eiqs "$search_regex" "$desktop" && {
(( found++ )) (( found++ ))
if "$verbose" ; then if "$verbose" ; then
echo "# $desktop" echo "# $desktop"