oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.27k stars 2.77k forks source link

bun shell interactive mode #14967

Open 7flash opened 1 week ago

7flash commented 1 week ago

What is the problem this feature would solve?

I want to write a server setup script in Bun shell, however I encounter following issue.

await Bun.$`curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh`;
rustup: Unable to run interactively. Run with -y to accept defaults, --help for additional options

What is the feature you are proposing to solve the problem?

bash interactive mode

What alternatives have you considered?

No response

7flash commented 1 week ago

Note, in this particular example, its simply solved by adding "-y" flag to skip interactive mode, however i wonder if its even possible to accept user input while running bun shell, as that would open up many possibilities.

guest271314 commented 1 week ago

Do you gain anything using the Bun shell, over just using Bash or Dash?

7flash commented 1 week ago

Do you gain anything using the Bun shell, over just using Bash or Dash?

Yes, with Bun Shell I can implement complex logic in between the commands, ie

const secret = await $`external-tool-requiring-user-passcode';
await Bun.password.hash(secret);
// ...
guest271314 commented 1 week ago

The closest I have gotten to this is over here in this related issue https://github.com/oven-sh/bun/issues/14693#issuecomment-2425379770.

pfgithub commented 1 week ago

Using Bun.spawn for interactive processes seems to work:

const proc = Bun.spawn({
    cmd: ["vim"],
    stdin: "inherit",
    stdout: "inherit",
    stderr: "inherit",
});
const exit_code = await proc.exited;
if(exit_code !== 0) {
    throw new Error("process exited with code: " + exit_code);
}
7flash commented 6 days ago

Using Bun.spawn for interactive processes seems to work:

const proc = Bun.spawn({ cmd: ["vim"], stdin: "inherit", stdout: "inherit", stderr: "inherit", }); const exit_code = await proc.exited; if(exit_code !== 0) { throw new Error("process exited with code: " + exit_code); }

Thanks, it actually works! Also compatible with gum https://github.com/charmbracelet/gum

const proc = Bun.spawn({
    cmd: ["gum", "choose", "fix", "feat"],
    stdin: "inherit",
    stdout: "inherit",
    stderr: "inherit",
});
const exit_code = await proc.exited;
if(exit_code !== 0) {
    throw new Error("process exited with code: " + exit_code);
}