oven-sh / bun

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

Implement commands in Bun shell #9716

Open Electroid opened 6 months ago

Electroid commented 6 months ago

This is a tracking issue for commands that we should implement as builtins in the Bun shell. Some of these are taken from GNU coreutils.

This is not an exhaustive list, we can add commands as we think it's a good idea to implement.

While these will already be generally available on most posix systems, having them in the Shell will also allow them to be readily available on Windows when using Bun Shell.

edimarlnx commented 5 months ago

I want to create a bun shell to use instead of bash, zsh, sh, etc. I started the simple project to think about how it is possible.

So, I have some questions:

  1. Is there a way to register a shell command using Javascript definition?

For example:

$.register('add', (n1,n2) => {
  return n1+n2; 
}) 

$`add 2 5`
  1. Is there a way to persist changes into shell "session"?

For example: When I use the command $cd DIRNAME, the work directory of the shell ($) changes to the new directory.

If these examples are possible, It will do a powerful to make a great shell alternative using Javascript.

thewh1teagle commented 4 months ago

It will be cool if Bun will support cross platform unzip for zip, 7z etc, and cross platform wget or similar which download a file (Windows doesn't have wget by default) and using fetch for download is slow.

LifeJustDLC commented 4 months ago

10174 update cp

With the power of cp, I can finally write some cross platform readable building scripts, to copy my manifest.json to dist. 😂

mlkt commented 2 months ago

Why not implement the exec command? Executing it to replace the current process is a crucial and convenient command.

Ptitet commented 1 month ago

Is it possible to add the wc command ? It is not available on Windows.

7flash commented 1 month ago

unfortunately, curl not working with bun shell

import { $ } from 'bun';

async function main() {
  const url = "https://jsonplaceholder.typicode.com/todos/1";

  const curlCommand = `curl -X GET ${url}`;

  try {
    const result = await $`${curlCommand.trim()}`;

    if (result.exitCode !== 0) {
      console.error(`Curl command failed with exit code ${result.exitCode}`);
      process.exit(1);
    }

    console.info(`Curl command succeeded with output:`);
    console.info(result.stdout);
  } catch (error) {
    console.error(`Request failed: ${error.message}`);
    process.exit(1);
  }
}

main();

throws an error

bun: command not found: /usr/bin/curl -X GET https://jsonplaceholder.typicode.com/todos/1

rametta commented 1 month ago

sed command would really be helpful too. find and replace is something I need often

7flash commented 1 month ago

It works well with running any of my scripts like

await $script.py ${args}.quiet();

Therefore I'm sure there must be a simple way to make it work with all installed programs like "curl" in example above