blob: 7f8ab5ebdcd4dc9eb7858aa6b15a4ad003173cd0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#!/bin/sh
#
# DESCRIPTION:
# parses a .desktop file, that matches in name to `$0`
# and executes the `Exec` value.
#
# INSTALL:
# ln -s <path/to/this/script> /usr/local/bin/app.desktop
#
set -e
basepath=$(dirname "$0" | sed 's#/bin#/share/applications#')
basename=$(basename "$0" | sed -e 's/^_//' -e 's/.desktop$//')
# try ~/.local/share/applications first:
XDG_DESKTOP_ENTRY_DIR=$HOME/.local/share/applications
if [ -e "${XDG_DESKTOP_ENTRY_DIR}/${basename}.desktop" ]; then
desktop=${XDG_DESKTOP_ENTRY_DIR}/${basename}.desktop
else
desktop=${basepath}/${basename}.desktop
fi
exe=$(
awk 'BEGIN{try=true;exe="";} /^;/{next} /^TryExec=/{try=gensub(/^TryExec=([^%]*).*$/, "\\1", "g")} /^Exec=/{if(exe==""){exe=gensub(/^Exec=([^%]*).*$/, "\\1", "g")}} END{if(system("command -v " try " >/dev/null")!=0){exit 1}; gsub(/\s$/, "", exe); print exe}' "$desktop"
)
set -x
exec sh -c "${exe} \"$*\""
|