summary refs log tree commit diff
path: root/bin/xdg-exec
diff options
context:
space:
mode:
Diffstat (limited to 'bin/xdg-exec')
-rwxr-xr-xbin/xdg-exec23
1 files changed, 20 insertions, 3 deletions
diff --git a/bin/xdg-exec b/bin/xdg-exec
index 787c502..e8f3ccb 100755
--- a/bin/xdg-exec
+++ b/bin/xdg-exec
@@ -1,7 +1,24 @@
 #!/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
+#
+
+XDG_DESKTOP_ENTRY_DIR=$HOME/.local/share/applications
 set -ex
 basepath=$(dirname "$0" | sed 's#/bin#/share/applications#')
 basename=$(basename "$0" | sed -e 's/^_//' -e 's/.desktop$//')
-desktop=${basepath}/${basename}.desktop
-bin=$(awk '/TryExec=/{split($0,l,"="); if (not system("command -v l[2]")){exit 1}} /Exec=/{print substr($0, index($0,"=")+1)}' "$desktop" | tr -d '\n' | sed "s/%.$//")
-exec $bin
+if [ -e "${XDG_DESKTOP_ENTRY_DIR}/${basename}.desktop" ]; then
+				desktop=${XDG_DESKTOP_ENTRY_DIR}/${basename}.desktop
+else
+				desktop=${basepath}/${basename}.desktop
+fi
+bin=$(awk '
+/^TryExec=/{split($0,l,"="); if(not system("command -v l[2]")){exit 1}}
+/^Exec=/{printf gensub(/Exec=([^%]+).*$/, "\\1", "")}
+' "$desktop" | sed 's/%.$//')
+exec ${bin} $@