Coder Social home page Coder Social logo

bun-self's Introduction

bun-self

Let's say you have a file called script.ts with the following content:

import { $ } from "bun";
await $`curl -s wttr.in`;

And you really want your friend to run it, so you decide to share a gist with them, but they are not as cool as you and don't have Bun installed yet. A problem.

But you won't even believe what happens next:

bunx bun-self script.ts

And you send this beauty to your friend instead (script.run.ts):

#!/usr/bin/env bash

/*/.this-doesnt-exist 2>/dev/null
## Please do not edit this part of the script, this is a loader created by "bunx bun-self"
if ! [ -x "$(command -v bun)" ]; then
    echo "Installing bun.sh"
    sleep 2
    curl -fsSL https://bun.sh/install | bash
    echo "Now let's run the script"
    echo ""
fi
bun $0
exit 0
#*/

// Script starts here
import { $ } from "bun";
await $`curl -s wttr.in`;

Your friend just has to run it either with

bash script.run.ts

or

chmod +x ./script.run.ts
./script.run.ts

They won't even know what hit them.

Of course it doesn't have to be a friend, you can hide that stuff in plain sight at your job with an innocent-looking "bash script.run.ts" in the "scripts" section of your package.json and no one even will notice that they are now happy Bun users.

References

bun-self's People

Contributors

jlarky avatar

Stargazers

Hatem Hosny avatar Aurélien Lourot avatar Nikola R. Hristov avatar

Watchers

 avatar  avatar

bun-self's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.