#!/bin/bash parse_desktop_file() { local file="$1" local section="" local mainexec="" local mainname="" while IFS= read -r line || [[ -n "$line" ]]; do if [[ "$line" =~ ^\;.* || "$line" =~ ^#.* || -z "$line" ]]; then continue fi if [[ "$line" =~ ^\[.*\]$ ]]; then section="${line:1:-1}" continue fi if [[ "$line" =~ ^([^=]+)=(.*)$ ]]; then key="${BASH_REMATCH[1]}" value="${BASH_REMATCH[2]}" # echo "[$section] $key = $value" if [ "$section" == "Desktop Entry" ]; then if [ "$key" == "Exec" ]; then mainexec=$value; fi if [ "$key" == "Name" ]; then mainname=$value; fi fi fi done < "$file" echo "{\"file\": \"$file\", \"name\": \"$mainname\", \"exec\": \"$mainexec\"}" } shopt -s nullglob IFS=':' read -r -a paths <<< "$XDG_DATA_DIRS:/home/$USER/.local/share/" for path in "${paths[@]}"; do AP=$(realpath "$path/applications") for appfile in $AP/*.desktop; do parse_desktop_file $appfile; done done shopt -u nullglob