#!/bin/sh # # DESCRIPTION: # parses a .desktop file, that matches in name to `$0` # and executes the `Exec` value. # # INSTALL: # ln -s /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} \"$*\""