swaywm / sway

i3-compatible Wayland compositor
https://swaywm.org
MIT License
14.55k stars 1.11k forks source link

exec quoting different from i3 (double quoted executables not working) #5931

Open mreppen opened 3 years ago

mreppen commented 3 years ago

Sway 1.5.1

Is this intentional?

Because the spec for .desktop files specify quoting, it breaks using i3-dmenu-desktop in Sway for such .desktop files

emersion commented 3 years ago

swaymsg exec "\"termite\"" works fine, and swaymsg exec "\"termite -t test\"" works fine too. So I guess we're incorrectly stripping too many quotes?

mreppen commented 3 years ago

Indeed. I would expect your second example to fail.

rpigott commented 3 years ago

@emersion those are both as expected. exec strips 1 layer of outer quotes, as it does in i3. https://i3wm.org/docs/userguide.html#exec_quoting

Similarly, i3-msg exec "\"test file\"" in i3 and swaymsg exec "\"test file\"" in sway have the same behavior for me. They both execute an executable with name "test" and argument "file".

If you want to run an executable "test file", use: swaymsg exec '"\"test file\""'. The '' are stripped by the shell, the "" are stripped by exec, and the inner \"test file\" is passed to the exec'd shell as "test file" so our command test file runs with no arguments.

rpigott commented 3 years ago

@mreppen could you give an example desktop file where i3 and sway differ? A debug log could help identify how sway interprets the commands.

mreppen commented 3 years ago

@RPigott Sure. But you don't need a desktop file to see that they are different:

~/test exec.sh:

#!/bin/bash
notify-send Works

Works: i3-msg 'exec "\"$HOME/test exec.sh\""' Does not work: swaymsg 'exec "\"$HOME/test exec.sh\""'

.desktop example:

~/.local/share/applications/myapp.desktop:

[Desktop Entry]
Name=My App
Exec="$HOME/test exec.sh"
Terminal=false
Type=Application

Running i3-dmenu-desktop and selecting "My App" in i3 works, but in Sway not.

I actually patched i3-dmenu-desktop to do more proper escaping before I realized that it already works in i3

rpigott commented 3 years ago

Well at least an example wasn't hard to find.

mreppen commented 2 years ago

EDIT: Nvm, this is similar but not relevant here. Will leave for somebody to find and hopefully save time from debugging other things

This is probably also related: It incorrectly quotes Exec entries. I have compared other launchers:

Exec=bash -c 'notify-send "asd"'

i3-dmenu-desktop sends "asd" whereas other launchers yield asd as expected.

REmerald commented 5 months ago

Also, for some weird reason (in exec_always { ... } block) 'notify-send "\\""' prints ", but 'notify-send "\\'"' prints \'. 'notify-send "\'"' doesn't print at all.

REmerald commented 5 months ago

I deleted my previous comments, the best workaroud is to use string concatenation:

exec_always {
    'notify-send ''"'"'"'"''"$(localectl status | grep "X11 Layout"  | sed -e "s/^.*X11 Layout: //" )"''"'"'"'"'
    # 'notify-send ' '"' "'" '"' '"$(localectl status | grep "X11 Layout"  | sed -e "s/^.*X11 Layout: //" )"' '"' "'" '"'
}

Backslash escaping works unreliably: \" works only on login, \\" works only on config reload.