Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support creating sub-shell with separate environment/cwd #298

Open
JohnnyCrazy opened this issue Jan 13, 2025 · 0 comments
Open

Support creating sub-shell with separate environment/cwd #298

JohnnyCrazy opened this issue Jan 13, 2025 · 0 comments

Comments

@JohnnyCrazy
Copy link

Hi,

Is something like within supported yet, see zx docs? I think it spawns a sub-shell under the hood, which allows to have a separate environment and also change the cwd isolated.

My use-case is to run build processes in different directories parallel, sth like this:

// in project1
await $`build`;
await cd("../cdk");
await Promise.all([
  within(async () => {
    await $`deploy-1`;
    await $`deploy-2`;
    await $`deploy-3`;
  }),
  within(async () => {
    await cd("../project2");
    await $`build`;
    await cd("../cdk");
    await $`deploy-4`;
  }),

I tried using $.build$({}) but it shares the cwd with the main $, doesn't it?

#!/usr/bin/env tsx
import $ from "dax-sh"; // "dax-sh" in Node
$.setPrintCommand(true);

const other$ = $.build$({});
$.cd("/tmp");

await other$`echo $PWD`;
await $`echo $PWD`;
❯ test_dax
> echo $PWD
/private/tmp
> echo $PWD
/private/tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant