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

Implement commands in Bun shell #9716

Open
18 of 41 tasks
Electroid opened this issue Mar 29, 2024 · 8 comments
Open
18 of 41 tasks

Implement commands in Bun shell #9716

Electroid opened this issue Mar 29, 2024 · 8 comments
Labels
shell Something to do with Bun as a shell tracking An umbrella issue for tracking big features

Comments

@Electroid
Copy link
Contributor

Electroid commented Mar 29, 2024

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.

  • cat
  • touch
  • mkdir
  • cd
  • echo
  • pwd
  • which
  • rm
  • mv
  • ls
  • exit
  • true
  • false
  • cp
  • timeout
  • yes
  • basename
  • realpath
  • dirname
  • mktemp
  • truncate
  • head
  • tail
  • cut
  • uniq
  • seq
  • sleep
  • tee
  • date
  • sha1sum
  • sha224sum
  • sha256sum
  • sha384sum
  • sha512sum
  • md5sum
  • sort
  • printenv
  • env
  • whoami
  • who
  • uptime

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
Copy link

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
Copy link

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
Copy link

#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
Copy link

mlkt commented Jul 30, 2024

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

@Ptitet
Copy link
Contributor

Ptitet commented Aug 4, 2024

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

@7flash
Copy link

7flash commented Aug 19, 2024

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
Copy link

rametta commented Aug 30, 2024

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

@7flash
Copy link

7flash commented Aug 30, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shell Something to do with Bun as a shell tracking An umbrella issue for tracking big features
Projects
None yet
Development

No branches or pull requests

8 participants