~kennylevinsen/public-inbox

wldash: Lex exec even when using custom opener v1 APPLIED

Maxim Baz: 1
 Lex exec even when using custom opener

 1 files changed, 3 insertions(+), 2 deletions(-)
#655803 .build.yml success
> Hmm, this does appear to cause somewhat annoying behavior. Specifically, it
> breaks use of `swaymsg exec` as a custom launcher, which for sway is more or
> less the suggested custom launcher.
Long story short, try setting your launcher as `swaymsg exec --` and it should work fine.
> I am considering reverting this patch. What was the use-case that required it?
Please don't! :)

This patch allows to properly distinguish app path from its arguments, there were a lot of underlying issues which were all caused by this.

To see a simple example, try the following shell script as a launcher, before and after this patch:

```
#!/bin/bash

app="$1"
shift
echo "Launching '$app' with args '$*'"
"$app" "$@"
```

This intentionally uses `echo`, so just call `wldash` from terminal and observe the output.

.desktop files to try:

`/usr/bin/chromium %u` - would fail because there is an extra space in the path, `/usr/bin/chromium ` is invalid path to executable.
`/usr/bin/chromium --enable-gpu-rasterization` - would fail because this entire string is not a path to executable either.

`swaymsg exec` is just "special" in a sense that it wants to distinguish arguments passed to `swaymsg` and arguments passed to the app, so in such cases a proper solution is to use `--` to distinguish the two.


Hope that helps!
Maxim Baz
> Why do you want to distinguish app path from its arguments if the goal isn't
> to call exec(3)?
Ah because it allows for creativity! :)

For example, I made an opener script that launches all apps in a new cgroup [1], and I make use of this feature for several reasons:

1. Put app name in cgroup name, to distinguish it easier
2. For terminal apps, set terminal's app_id to the app name (so I can distinguish terminal that runs neomutt, set specific icon, etc)
3. For terminal apps I can prepend terminal itself, so "$ cglaunch --term neomutt" would actually end up calling "$ kitty --class neomutt neomutt"
> Anyway, if this enables a use-case without breaking the common use-cases,
> then I'm fine with it.
Awesome, thanks! :)

1: https://github.com/maximbaz/dotfiles/blob/master/.local/bin/cglaunch

--
Maxim Baz
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~kennylevinsen/public-inbox/patches/27626/mbox | git am -3
Learn more about email & git

[PATCH wldash] Lex exec even when using custom opener Export this patch

This fixes a few bugs I found related to custom opener.

Instead of sending the entire exec as a single argument, this properly splits the command, trims trailing whitespaces, and lets the receiving opener iterate over terms.
---
 src/widgets/launcher.rs | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/widgets/launcher.rs b/src/widgets/launcher.rs
index 796f1a2..081f266 100644
--- a/src/widgets/launcher.rs
+++ b/src/widgets/launcher.rs
@@ -420,12 +420,13 @@ impl<'a> Widget for Launcher<'a> {
                                    &self.app_opener
                                };

                                let mut lexed = shlex::split(&exec).unwrap();
                                let lexed = if !prefix.is_empty() {
                                    let mut prefix = shlex::split(prefix).unwrap();
                                    prefix.push(exec);
                                    prefix.append(&mut lexed);
                                    prefix
                                } else {
                                    shlex::split(&exec).unwrap()
                                    lexed
                                };
                                if !lexed.is_empty() {
                                    let _ =
-- 
2.34.1
wldash/patches/.build.yml: SUCCESS in 2m22s

[Lex exec even when using custom opener][0] from [Maxim Baz][1]

[0]: https://lists.sr.ht/~kennylevinsen/public-inbox/patches/27626
[1]: mailto:git@maximbaz.com

✓ #655803 SUCCESS wldash/patches/.build.yml https://builds.sr.ht/~kennylevinsen/job/655803
Applied, thanks!
Hmm, this does appear to cause somewhat annoying behavior. 
Specifically, it breaks use of `swaymsg exec` as a custom launcher, 
which for sway is more or less the suggested custom launcher.

I am considering reverting this patch. What was the use-case that 
required it?