Easier Shell Scripting with ZX (first look)

Ғылым және технология

We've all had to write bash scripts from time to time, but maybe you prefer to write JavaScript. If that's the case, you'll love ZX, a tool from Google that blends the power of shell scripting with the familiarity of JavaScript.

Пікірлер: 31

  • @karamuto1565
    @karamuto1565 Жыл бұрын

    Really interesting maybe I will pitch this to my team in the new year as we only have maybe 3 people that can actually handle the more complex shell scripts we have.

  • @volodymyrvorona2250
    @volodymyrvorona2250 Жыл бұрын

    Another great video. Thank you!

  • @zeenuexe8362
    @zeenuexe836211 ай бұрын

    As someone who doesn't know how to do anything complex in bash, this is fantastic. i will try it out.

  • @nithinrajendran3091
    @nithinrajendran3091 Жыл бұрын

    peter parker in the alternate universe

  • @ashwinbhargava3011
    @ashwinbhargava3011 Жыл бұрын

    As a web developer, I want to give Google a kiss. I literally hate Bash's syntax because I always had to Google everything every time I wanted to script something. And when I started using Fish, POSIX compliance was a headache. I was thinking of creating a wrapper module for Node.js exactly like this. Great video btw.

  • @irlshrek
    @irlshrek Жыл бұрын

    dude, awesome find!

  • @kamertonaudiophileplayer847
    @kamertonaudiophileplayer847 Жыл бұрын

    It s a great idea, I also start using rb.

  • @HyperFocusMarshmallow
    @HyperFocusMarshmallow Жыл бұрын

    Looks nice.

  • @karixening
    @karixening Жыл бұрын

    Check out the deno package called rush. Just a prototype, but similar concept. I think Deno is really good for scripting since you don't have to worry about installing any dependencies.

  • @andrew-burgess

    @andrew-burgess

    Жыл бұрын

    Thanks, I’ll check it out!

  • @sck3570
    @sck3570 Жыл бұрын

    that's dope 👌

  • @starseven4736
    @starseven4736 Жыл бұрын

    babashka is awesome way to script tooo

  • @Fullflexno
    @Fullflexno Жыл бұрын

    Supercool +1 sub!

  • @christianalares
    @christianalares Жыл бұрын

    Have you managed to make this work with TypeScript? I would like to rewrite a CLI i made before but with zx. But if I'm not able to do it with TS it's not worth it imo.

  • @avi7278

    @avi7278

    Жыл бұрын

    Does not seem like the compiler could handle it. Those literals prefixed with $ are not valid syntax, are they?

  • @loic.bertrand

    @loic.bertrand

    Жыл бұрын

    ​@@avi7278it is valid JS and TS syntax, it's called a Tagged Templated Literal 🙂 here '$' is tag function which processes the template literal as well as its "dynamic" values (${...} parts in the template)

  • @SuperQuwertz

    @SuperQuwertz

    4 ай бұрын

    You can use bun to run the script without transpiling it

  • @SuperQuwertz

    @SuperQuwertz

    4 ай бұрын

    Or just use JSDocs Or transpile it (which isnt that nice imo)

  • @RahulGupta-vw8jr
    @RahulGupta-vw8jr Жыл бұрын

    While this is cool, the utility of bash commands are that they can be run on any system with the same OS. Using ZX will create a dependency on having node installed and this package installed. Now you need to know both bash and JS use this. Why not just use execSync package is JS? But if you are using it for personal project or you are the main mainter of a project this make sense.

  • @PaulJohnLeonard

    @PaulJohnLeonard

    Жыл бұрын

    I currently use execSync. I will probably switch to zx because it looks like the code will have less boiler plate and be easier to read. I dont mind the one off devop dependancy.

  • @salman0ansari
    @salman0ansari Жыл бұрын

    cool ✌🏻

  • @replikvltyoutube3727
    @replikvltyoutube3727 Жыл бұрын

    As much as it looks nice, it seems to overly complicate things

  • @kris10an64

    @kris10an64

    Жыл бұрын

    How exactly?

  • @jaysistar2711

    @jaysistar2711

    Жыл бұрын

    No, I've been doing this sort of thing with Jake, a Make-like task runner with tasks written in JavaScript, and this greatly simplifies things.

  • @allisondealmeida
    @allisondealmeida Жыл бұрын

    are you using neovim?

  • @andrew-burgess

    @andrew-burgess

    Жыл бұрын

    I am! More about my setup here: shaky.sh/tools/

  • @voidmind
    @voidmind Жыл бұрын

    You kind of look like Linus Torvalds when he was young

  • @ankanroy2931
    @ankanroy2931 Жыл бұрын

    nop, if i had to use this might just use python

  • @andrew-burgess

    @andrew-burgess

    Жыл бұрын

    Fair enough! I don’t know much python, is there a good way to get the output of shell commands, or is there just a better way to do it?

  • @twothreeoneoneseventwoonefour5

    @twothreeoneoneseventwoonefour5

    Жыл бұрын

    @@andrew-burgess yes there are a lot of utils in python to interact with the shell and it is pretty easy and straightforward. subprocess, shutil is often good enough for most tasks though to get only output iirc(didnt use python for some time) there was subprocess.check_output or something like that. I used it to automate some stuff, getting output from ffprobe and feeding it to ffmpeg for example. subprocess have both sync and async procesd spawn, and as I said above can also get output of a command or a cli program easily

  • @acquite
    @acquite Жыл бұрын

    i wrote my own implementation without knowing about this.. thanks for allowing me to discover it now. prior to this i was using the exec function from node:child-process as follows. it very much does the same thing that this is doing, just custom the following is an example of how it was written and how it can be used ```ts import { exec, ExecException } from 'child_process'; class Shell { static async run(command: string = 'ls', after = (stderr: ExecException | null, stdout: string): void => {}): Promise { return await new Promise((resolve): void => { exec(command, (stderr, stdout): void => { after(stderr, stdout); resolve(stdout); }); }); } } await Shell.run(`Echo "Hello World!"`, (_, stdout) => process.stdout.write(stdout)) const fonts = await Shell.run(`ls ./Fonts`) ``` this works fine but it requires some know-how of how promises work and how to wrap exec like this. overall zx makes this easier. thank you again!

Келесі