Print XDG Desktop Definition for Application

For an application given by „application name“ or „executable name“, output the corresponding .desktop file, if any:

find_desktop() {
  local search=$1
  local IFS=":"

  for i in $XDG_DATA_DIRS ; do
    a="$i/applications"
    [ -d $a ] && for d in "$a"/*.desktop ; do
      grep -q -e "^Name=.*$search" -e "^Exec=.*$search" "$d" && {
        echo "# $d:"
        grep -Ev '^(Comment|GenericName|Keywords|Name\[)' "$d"
      }
    done
  done
}

Try it:

find_desktop gnome-terminal