summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorMarco Rebhan <me@dblsaiko.net>2022-11-21 19:37:02 +0100
committerMarco Rebhan <me@dblsaiko.net>2023-03-26 12:47:52 +0200
commitb48f6118c489beda224223dc66589195b387a9d0 (patch)
tree89913756359c0f5af050fecdc192e6f17e3a047e /pkgs/build-support
parent1c0306c913bef5ffff5f91b373153ad980bc4f2d (diff)
downloadnixpkgs-b48f6118c489beda224223dc66589195b387a9d0.tar
nixpkgs-b48f6118c489beda224223dc66589195b387a9d0.tar.gz
nixpkgs-b48f6118c489beda224223dc66589195b387a9d0.tar.bz2
nixpkgs-b48f6118c489beda224223dc66589195b387a9d0.tar.lz
nixpkgs-b48f6118c489beda224223dc66589195b387a9d0.tar.xz
nixpkgs-b48f6118c489beda224223dc66589195b387a9d0.tar.zst
nixpkgs-b48f6118c489beda224223dc66589195b387a9d0.zip
desktopToDarwinBundle: Return at most 1 literal match from desktop file
This fixes multiple entries being returned from getDesktopParam, e.g. in the
case of localized key names: 'Name', 'Name[de]', and makes this function to
match this key exactly instead of a pattern for the same reason.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh25
1 files changed, 19 insertions, 6 deletions
diff --git a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh
index 83ea7de3ee2..f52b50608f9 100644
--- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh
+++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh
@@ -2,12 +2,25 @@
 fixupOutputHooks+=('convertDesktopFiles $prefix')
 
 # Get a param out of a desktop file. First parameter is the file and the second
-# is a pattern of the key who's value we should fetch.
+# is the key who's value we should fetch.
 getDesktopParam() {
-    local file="$1";
-    local pattern="$2";
+    local file="$1"
+    local key="$2"
+    local line k v
+
+    while read -r line; do
+        if [[ "$line" = *=* ]]; then
+            k="${line%%=*}"
+            v="${line#*=}"
+
+            if [[ "$k" = "$key" ]]; then
+                echo "$v"
+                return
+            fi
+        fi
+    done < "$file"
 
-    awk -F "=" "/${pattern}/ {print \$2}" "${file}"
+    return 1
 }
 
 # Convert a freedesktop.org icon theme for a given app to a .icns file. When possible, missing
@@ -190,14 +203,14 @@ processExecFieldCodes() {
 convertDesktopFile() {
     local -r file=$1
     local -r sharePath=$(dirname "$(dirname "$file")")
-    local -r name=$(getDesktopParam "${file}" "^Name")
+    local -r name=$(getDesktopParam "${file}" "Name")
     local -r macOSExec=$(getDesktopParam "${file}" "X-macOS-Exec")
     if [[ "$macOSExec" ]]; then
       local -r exec="$macOSExec"
     else
       local -r exec=$(processExecFieldCodes "${file}")
     fi
-    local -r iconName=$(getDesktopParam "${file}" "^Icon")
+    local -r iconName=$(getDesktopParam "${file}" "Icon")
     local -r squircle=$(getDesktopParam "${file}" "X-macOS-SquircleIcon")
 
     mkdir -p "${!outputBin}/Applications/${name}.app/Contents/MacOS"