summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTill Maas <opensource@till.name>2014-02-26 15:26:59 +0100
committerRex Dieter <rdieter@math.unl.edu>2014-03-30 17:29:00 -0500
commit316b9adc05c6d871360afb1195939c5fc975ccff (patch)
tree6f1dbdc677c5cda79739dbe0e943aaf4035e3550
parent3eaf93ab3303e14813885b6b743b48a1c3b5a6ab (diff)
xdg-open: Expand %i and %c from Exec
-rw-r--r--scripts/xdg-open.in29
1 files changed, 26 insertions, 3 deletions
diff --git a/scripts/xdg-open.in b/scripts/xdg-open.in
index 1f768d8..e7a15a9 100644
--- a/scripts/xdg-open.in
+++ b/scripts/xdg-open.in
@@ -36,6 +36,17 @@ last_word()
echo "$rest"
}
+# Get the value of a key in a .desktop file.
+# Example: Use get_key foo.desktop Exec
+# to get the values of the Exec= key
+get_key()
+{
+ local file="${1}"
+ local key="${2}"
+
+ grep -E "^${key}=" "${file}" | cut -d= -f 2-
+}
+
open_darwin()
{
open "$1"
@@ -137,11 +148,23 @@ search_desktop_file()
fi
if [ -r "$file" ] ; then
- command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
+ command="$(get_key "${file}" "Exec" | first_word)"
command_exec=`which $command 2>/dev/null`
- arguments="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | last_word`"
+ arguments="$(get_key "${file}" "Exec" | last_word)"
arg_one="`echo "$arg" | sed 's/[&*\\]/\\\\&/g'`"
- arguments_exec="`echo "$arguments" | sed -e 's*%[fFuU]*"'"$arg_one"'"*g'`"
+ icon="$(get_key "${file}" "Icon")"
+ if [ "${icon}" != "" ]
+ then
+ icon="--icon '${icon}'"
+ else
+ icon="''"
+ fi
+ # FIXME: Actually LC_MESSAGES should be used as described in
+ # http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s04.html
+ localised_name="'$(get_key "${file}" "Name")'"
+ arguments_exec="$(echo "$arguments" | sed -e 's*%[fFuU]*"'"$arg_one"'"*g' \
+ -e 's*%i*'"$icon"'*g' \
+ -e 's*%c*'"$localised_name"'*g')"
if [ -x "$command_exec" ] ; then
if echo "$arguments" | grep -iq '%[fFuU]' ; then