summary refs log tree commit diff
path: root/pkgs/build-support/setup-hooks
diff options
context:
space:
mode:
authorDomen Kožar <domen@dev.si>2022-04-20 12:24:01 +0100
committerGitHub <noreply@github.com>2022-04-20 12:24:01 +0100
commit36bbcc2a4a38e8410431ec7491fbbeaf434c0682 (patch)
tree8dd04a2f964ef5dd9c4a6fc0f5daf746b32d01da /pkgs/build-support/setup-hooks
parent9268d492f36a01d87233108dc08e073c63d22597 (diff)
parent261b73652131421cd562873191060b02b56db1fe (diff)
downloadnixpkgs-36bbcc2a4a38e8410431ec7491fbbeaf434c0682.tar
nixpkgs-36bbcc2a4a38e8410431ec7491fbbeaf434c0682.tar.gz
nixpkgs-36bbcc2a4a38e8410431ec7491fbbeaf434c0682.tar.bz2
nixpkgs-36bbcc2a4a38e8410431ec7491fbbeaf434c0682.tar.lz
nixpkgs-36bbcc2a4a38e8410431ec7491fbbeaf434c0682.tar.xz
nixpkgs-36bbcc2a4a38e8410431ec7491fbbeaf434c0682.tar.zst
nixpkgs-36bbcc2a4a38e8410431ec7491fbbeaf434c0682.zip
Merge pull request #165112 from toonn/darwin-bundle-Exec-field-codes
desktopToDarwinBundle: Patch Exec field codes
Diffstat (limited to 'pkgs/build-support/setup-hooks')
-rw-r--r--pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh24
1 files changed, 22 insertions, 2 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 d54af90b688..72c1b973666 100644
--- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh
+++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh
@@ -163,7 +163,7 @@ convertIconTheme() {
     }
 
     iconsdir=$(getIcons "$sharePath" "apps/${iconName}" "$theme")
-    if [[ -n "$(ls -1 "$iconsdir/"*)" ]]; then
+    if [[ -n "$(ls -A1 "$iconsdir")" ]]; then
         icnsutil compose --toc "$out/${iconName}.icns" "$iconsdir/"*
     else
         echo "Warning: no icons were found. Creating an empty icon for ${iconName}.icns."
@@ -171,12 +171,32 @@ convertIconTheme() {
     fi
 }
 
+processExecFieldCodes() {
+  local -r file=$1
+  local -r execRaw=$(getDesktopParam "${file}" "Exec")
+  local -r execNoK="${execRaw/\%k/${file}}"
+  local -r execNoKC="${execNoK/\%c/$(getDesktopParam "${file}" "Name")}"
+  local -r icon=$(getDesktopParam "${file}" "Icon")
+  local -r execNoKCI="${execNoKC/\%i/${icon:+--icon }${icon}}"
+  local -r execNoKCIfu="${execNoKCI/\%[fu]/\$1}"
+  local -r exec="${execNoKCIfu/\%[FU]/\$@}"
+  if [[ "$exec" != "$execRaw" ]]; then
+    echo 1>&2 "desktopToDarwinBundle: Application bundles do not understand desktop entry field codes. Changed '$execRaw' to '$exec'."
+  fi
+  echo "$exec"
+}
+
 # For a given .desktop file, generate a darwin '.app' bundle for it.
 convertDesktopFile() {
     local -r file=$1
     local -r sharePath=$(dirname "$(dirname "$file")")
     local -r name=$(getDesktopParam "${file}" "^Name")
-    local -r exec=$(getDesktopParam "${file}" "Exec")
+    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 squircle=$(getDesktopParam "${file}" "X-macOS-SquircleIcon")