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 IFS=":"
  local xdg_data_dirs=${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
  local search=$1

  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