This hook runs as root after a pacman transaction. Never point Exec at a script or package list writable by an ordinary user. Install both under root-owned paths; every ancestor directory must also be protected from user writes.
Save this as ap in your working directory for review, then install it as shown below. It handles simple, unquoted executable names in the first Exec= line only; quoted executable paths and Desktop Actions need a Desktop Entry-aware implementation rather than this small patcher.
#!/bin/bashset -euo pipefail[[ "$EUID" -eq 0 ]] || { printf 'Run through the root-owned pacman hook.\n' >&2; exit 1; }PARAM="--enable-wayland-ime"LIST="/etc/desktop-wayland-ime/apps.list"
modify_desktop() { local file="$1" exec_line command rest [[ -f "$file" && ! -L "$file" ]] || return 0 exec_line=$(grep -m1 '^Exec=' "$file") || return 0 # Only simple, unquoted executable tokens; skip other grammar safely. if [[ "$exec_line" =~ ^Exec=([[:alnum:]_./-]+)([[:blank:]].*)?$ ]]; then command="${BASH_REMATCH[1]}" rest="${BASH_REMATCH[2]:-}" else return 0 fi [[ " $rest " == *" $PARAM "* ]] && return 0 # Replace only the executable token; leave arguments (including & and |) untouched. sed -i "0,/^Exec=/s|^Exec=[^[:blank:]]*|& $PARAM|" "$file"}
while IFS= read -r app || [[ -n "$app" ]]; do [[ -z "$app" || "$app" == \#* ]] && continue # Accept desktop basenames only, never paths or traversal. [[ "$app" =~ ^[[:alnum:]_-][[:alnum:]_.-]*$ ]] || { printf 'Invalid desktop basename.\n' >&2; exit 1; } modify_desktop "/usr/share/applications/$app.desktop"done < "$LIST"Save the package list as apps.list, for example:
cursor-cursorqqcherry-studioInstall the reviewed script and list (the working copies are not executed by the hook):
sudo install -d -o root -g root -m 0755 /etc/desktop-wayland-imesudo install -o root -g root -m 0755 ap /usr/local/sbin/desktop-wayland-imesudo install -o root -g root -m 0644 apps.list /etc/desktop-wayland-ime/apps.listCreate /etc/pacman.d/hooks/desktop-wayland-ime.hook with root
/usr/local/sbin are root-owned and not writable by ordinary users; if those directories are already user-writable, repair that prerequisite before installing anything.
[Trigger]Operation = InstallOperation = UpgradeType = PackageTarget = *
[Action]Description = Adding --enable-wayland-ime to selected .desktop filesWhen = PostTransactionExec = /usr/local/sbin/desktop-wayland-imeThe hook modifies selected package-owned files in /usr/share/applications; package upgrades can overwrite them again. A user-level desktop override is an alternative when the setting is only for one account.
Test the parser/idempotence against disposable desktop fixtures before installing, rather than performing a system upgrade only to test a hook. After installation, inspect ownership, mode and the modified Exec= lines during an independently planned package transaction. The earlier personal paru -Syu observation was not rerun for this revised hook; no package upgrade or root execution was performed in this review.