62 lines
2.1 KiB
Diff
62 lines
2.1 KiB
Diff
|
From 316b9adc05c6d871360afb1195939c5fc975ccff Mon Sep 17 00:00:00 2001
|
||
|
From: Till Maas <opensource@till.name>
|
||
|
Date: Wed, 26 Feb 2014 15:26:59 +0100
|
||
|
Subject: [PATCH 9/9] xdg-open: Expand %i and %c from Exec
|
||
|
|
||
|
---
|
||
|
scripts/xdg-open.in | 29 ++++++++++++++++++++++++++---
|
||
|
1 file 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
|
||
|
--
|
||
|
1.9.0
|
||
|
|