Update Nov 3 2024:
-
- There is an update to this article that provides this script as commandline utility.
- There is also a Git repository.
For an application given by „application name“ or „executable name“, output the corresponding .desktop file, if any:
#!/bin/sh
IFS=":"
xdg_data_dirs=${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
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
To try this code out, save it to /usr/local/bin/xdg-desktop-search, make it executable and test it, for example, as follows:
xdg-desktop-search gnome-terminal
This article is part of series "Shells and related Scripting Languages":
- GNU find hat keine Option „-older“ …
- Bourne to Bourne Again Shell Forward Compatibility
- Print XDG Desktop Definition for Application
- Find Files by Size given in Bytes
- Using sed or awk to ensure a specific last Line in a Text
- Make a Bourne Again Shell Script Log its Output to a File
- Maintaining Multi-Line „stat“ Formats using Bourne Again Shell
- Print all indented Lines following a non-indented Line