auto add param to desktop file

add this script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
PARAM="--enable-wayland-ime"

modify_desktop() {
local file="$1"

if grep -q "Exec=.*$PARAM" "$file"; then
return 0
fi

local exec_line=$(grep -m1 '^Exec=' "$file")

if [[ "$exec_line" =~ [[:space:]] ]]; then
sudo sed -i "0,/^Exec=/s|\(Exec=[^[:space:]]*[[:space:]]\)|\1$PARAM |" "$file"
else
sudo sed -i "0,/^Exec=/s|^Exec=.*|& $PARAM|" "$file"
fi
}

# change to your package list path
for app in $(cat /home/Kita/.local/bin/ap.lst); do
desktop_file="/usr/share/applications/$app.desktop"
if [[ -f "$desktop_file" ]]; then
modify_desktop "$desktop_file"
fi
done

add package list such as

1
2
3
cursor-cursor
qq
cherry-studio

add pacman hook to /etc/pacman.d/hooks/whateveryoucall.hook

1
2
3
4
5
6
7
8
9
10
11
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = *

[Action]
Description = Adding --enable-wyaland-ime to .desktop files
When = PostTransaction
Exec = /home/Kita/.local/bin/ap #change to your script path

after all package upgrade, this script will run and add --enable-wayland-ime to the Exec line of the specified .desktop files.

try sudo pacman -Syu to test it.

i use paru -Syu to test it, it works.