~sircmpwn/aerc

8 4

Variable substitution for the exec command

Details
Message ID
<C4I5YLOEYFQK.1IYEXL05ECPYS@bladestealth>
DKIM signature
pass
Download raw message
Hi, 
I'm adding a simple variable substitution for the exec command so I can sync my
maildirs with a shortcut from aerc.
What would be the prefered format, something like `{acount}` and `{folder}`
or %a and %f.
Details
Message ID
<20200730173849.md75fawtvbmhmspg@feather.localdomain>
In-Reply-To
<C4I5YLOEYFQK.1IYEXL05ECPYS@bladestealth> (view parent)
DKIM signature
pass
Download raw message
On Tue, Jul 28, 2020 at 11:52:56AM +0200, Nicolai Dagestad wrote:
> I'm adding a simple variable substitution for the exec command so I can sync my
> maildirs with a shortcut from aerc.
> What would be the prefered format, something like `{acount}` and `{folder}`
> or %a and %f.

I prefer the printf syntax... allows us to reuse the code / UX from the index
format.
However we will need to have a way to escape the substitution, so that you can still
pipe stuff into commands containing printf(1) or some such.

Cheers,
Reto
Details
Message ID
<KOeH1fXD8v3en3LwwGkjIh0wlmKhlsyD5wMSW2Jqou6nSeHHAFePNJWqT3FNLUoE8cbvIvVqaSbRRo7-xAG2mgqze4H9u7jp7xSpP3aQgeI=@emersion.fr>
In-Reply-To
<C4I5YLOEYFQK.1IYEXL05ECPYS@bladestealth> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
On Tuesday, July 28, 2020 11:52 AM, Nicolai Dagestad <nicolai@dagestad.fr> wrote:

> Hi,
> I'm adding a simple variable substitution for the exec command so I can sync my
> maildirs with a shortcut from aerc.
> What would be the prefered format, something like `{acount}` and `{folder}`
> or %a and %f.

These solutions would have the downside of not allowing proper quoting.
If the folder contains a space or a quote, I don't think it's possible
to come up with a solution that works.

An alternative would be to set env variables and let the shell perform
the expansion. So it would be something like $account and $folder.
Details
Message ID
<1D38CCA9-556A-4874-9A00-970A943DCF18@labrat.space>
In-Reply-To
<KOeH1fXD8v3en3LwwGkjIh0wlmKhlsyD5wMSW2Jqou6nSeHHAFePNJWqT3FNLUoE8cbvIvVqaSbRRo7-xAG2mgqze4H9u7jp7xSpP3aQgeI=@emersion.fr> (view parent)
DKIM signature
pass
Download raw message
On 30 July 2020 20:20:07 CEST, Simon Ser <contact@emersion.fr> wrote:

>These solutions would have the downside of not allowing proper quoting.
>If the folder contains a space or a quote, I don't think it's possible
>to come up with a solution that works.
>
>An alternative would be to set env variables and let the shell perform
>the expansion. So it would be something like $account and $folder.

hm, didn't think of that.
Env vars sounds like a compromise, what do you think?
Details
Message ID
<C4KSV71P609H.3U4WAQ3HBA78B@bladestealth>
In-Reply-To
<KOeH1fXD8v3en3LwwGkjIh0wlmKhlsyD5wMSW2Jqou6nSeHHAFePNJWqT3FNLUoE8cbvIvVqaSbRRo7-xAG2mgqze4H9u7jp7xSpP3aQgeI=@emersion.fr> (view parent)
DKIM signature
pass
Download raw message
> An alternative would be to set env variables and let the shell perform
> the expansion. So it would be something like $account and $folder.

The exec command doesn't use the shell to execute the command though. 
But I suppose that could be changed.
Details
Message ID
<C4KWN9U9BS01.R55ZFAEQBMUO@tarazed>
In-Reply-To
<C4KSV71P609H.3U4WAQ3HBA78B@bladestealth> (view parent)
DKIM signature
missing
Download raw message
On Fri Jul 31, 2020 at 2:15 PM CEST, Nicolai Dagestad wrote:
> > An alternative would be to set env variables and let the shell perform
> > the expansion. So it would be something like $account and $folder.
>
> The exec command doesn't use the shell to execute the command though.
> But I suppose that could be changed.

It does. See src/item/command.c, line 73:

    execl("/bin/sh", "/bin/sh", "-c", cmd, NULL);

It does not use the users shell (which would introduce a lot of
annoyances), but it does use a shell. That is probably even
documented in the man page somewhere, IIRC.

You can try it. Set as a button command
`notify-send $LAVALAUNHER_OUTPUT_NAME`. Since it runs in a shell and
the env var is set, it should return the name of the output. It does
on my machine.


Friendly greetings,
Leon Plickat
Details
Message ID
<C4KWUCT9BXVG.21ANNMZ8J3E34@bladestealth>
In-Reply-To
<C4KWN9U9BS01.R55ZFAEQBMUO@tarazed> (view parent)
DKIM signature
pass
Download raw message
On Fri Jul 31, 2020 at 5:12 PM CEST, Leon Plickat wrote:
> It does. See src/item/command.c, line 73:
> execl("/bin/sh", "/bin/sh", "-c", cmd, NULL);

We are in the aerc mailing list though, not lavalauncher :p
Details
Message ID
<C4KWUL6NWR3D.1ZGP8F3ASSJN2@tarazed>
In-Reply-To
<C4KWUCT9BXVG.21ANNMZ8J3E34@bladestealth> (view parent)
DKIM signature
missing
Download raw message
On Fri Jul 31, 2020 at 5:22 PM CEST, Nicolai Dagestad wrote:
> On Fri Jul 31, 2020 at 5:12 PM CEST, Leon Plickat wrote:
> > It does. See src/item/command.c, line 73:
> > execl("/bin/sh", "/bin/sh", "-c", cmd, NULL);
>
> We are in the aerc mailing list though, not lavalauncher :p

Damn, sorry for the noise. :(

I should probably a) sleep more and b) employ some way to easier see
what mailinglist a mail comes from.


Friendly greetings,
Leon Plickat
Details
Message ID
<20200801064910.zpihqosyg7fwhaze@feather.localdomain>
In-Reply-To
<C4KSV71P609H.3U4WAQ3HBA78B@bladestealth> (view parent)
DKIM signature
pass
Download raw message
On Fri, Jul 31, 2020 at 02:15:14PM +0200, Nicolai Dagestad wrote:
> > An alternative would be to set env variables and let the shell perform
> > the expansion. So it would be something like $account and $folder.
>
> The exec command doesn't use the shell to execute the command though.
> But I suppose that could be changed.

No need.
If users want to do the expansion in a shell, they should spawn a shell.

Commands can use env vars just fine by themselves.

Consider this snippet:
```
package main

import (
	"log"
	"os"
	"os/exec"
)

func main() {
	proc := exec.Command("env")
	env := os.Environ()
	env = append(env, "aerc_greeting=hello")
	proc.Env = env
	proc.Stdout = os.Stdout
	err := proc.Start()
	if err != nil {
		log.Fatal(err)
	}
	err = proc.Wait()
	if err != nil {
		log.Fatal(err)
	}
}
```

env will happily print the aerc_greeting env var, no shell involved.
I don't think we should force sh for the :exec cmd.

Greetings,
Reto
Export thread (mbox)