mise icon indicating copy to clipboard operation
mise copied to clipboard

Cache env vars with slow exec function calls in templating

Open pdecat opened this issue 1 year ago • 5 comments

Setting environment variables from commands that are slow affects all prompt executions, e.g. setting:

mise env-vars TEST_MISE="{{exec(command='sleep 1')}}"

which translates into:

[env]
TEST_MISE = "{{exec(command='sleep 1')}}"

will add a 1 second latency at each prompt.

It would be awesome to allow caching such commands.

Note: that's just an example, my actual use case is invoking gopass to set an environment variable with GPG operations depending on my yubikey.

pdecat avatar Dec 24 '23 10:12 pdecat

I think me putting caching around templates is too difficult. I have no idea what sort of invalidation logic would work since I have no idea what people might be putting in their files.

Perhaps what we could do though is expose caching inside the templates so you could read/write to the cache instead of performing expensive computations.

jdx avatar Dec 24 '23 17:12 jdx

Caching would be great, please have in mind that exec templates can be used to retrieve secrets so env vars shouldn't be cached/stored on disk unencrypted.

i.e.

[env]
TOKEN = "{{exec(command='gopass show --password token')}}"

hinricht avatar Jun 07 '24 13:06 hinricht

Oh just realized this use-case was the original motivation for this FR :)

hinricht avatar Jun 07 '24 13:06 hinricht