Biont/sway-launcher-desktop

Env vars in .desktop files are not handled properly

Biont opened this issue · 5 comments

Biont commented

I will just copy/paste the report of @nstickney here

PROBLEM:
Some *.desktop files include not just the command, but also environment variables, in the Exec line, i.e. "Exec=env GDK_BACKEND=x11 /opt/minecraft-launcher/minecraft-launcher". This is apparently a standard pattern, but swaymsg -t command "$command" leads to Error: Unknown/invalid command 'env'. I tried changing the Exec line to /usr/bin/env, but I get a similar message: Error: Unknown/invalid command '/usr/bin/env'.

SOLUTION:
I changed the way the $command variable is formatted by removing the line break and replacing it with a space. Then, when running the command, I cut out env using bash string substitution.

EDIT:
Note, I also changed the ordering of the $DIRS hoping to make the ~/.local entry override the others, but I don't believe it has any effect.


Personal note: I believe part of the problem is that awk will see additional columns in an Exec= line like this: Exec=env GDK_BACKEND=x11 /opt/minecraft-launcher/minecraft-launcher since there is one more equals sign in there which we are using as a delimiter

@nstickney You can also fix the newline by using printf instead of print as I'm doing in #1.

Biont commented

@nstickney From what I can tell, this looks good now after the changes made by @joefiorini.
The minecraft-launcher.desktop file now produces the following command: cd /opt/minecraft-launcher/ && env GDK_BACKEND=x11 /opt/minecraft-launcher/minecraft-launcher

I added a test case for this specific issue and you can debug things more easily using ./sway-launcher-desktop.sh generate-command /path/to/application.desktop

@Biont the command as you wrote it actually fails for me:

[bash 5.0.11] $ swaymsg -t command "cd /opt/minecraft-launcher/ && env GDK_BACKEND=x11 /opt/minecraft-launcher/minecraft-launcher"
Error: Unknown/invalid command 'cd'

Is no one else seeing this behavior? swaymsg -t command doesn't seem to allow shell built-ins for me.

swaymsg exec seems to fix it. This issue can be closed.

Biont commented

Great. Thanks for your input @nstickney