[HN Gopher] Shelljs - Portable Unix shell commands for Node.js
       ___________________________________________________________________
        
       Shelljs - Portable Unix shell commands for Node.js
        
       Author : chetangoti
       Score  : 44 points
       Date   : 2021-05-07 07:17 UTC (2 days ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | mrbungie wrote:
       | Does anybody know a project doing something similar but in
       | Python?
        
         | [deleted]
        
         | kasbah wrote:
         | `sh` might be what you are looking for.
         | 
         | https://amoffat.github.io/sh/
        
       | kordlessagain wrote:
       | Say goodbye to gnarly shell scripts? Oh Nodejs you're funny!
        
         | azalemeth wrote:
         | To my naive mind this seems like a sure-fire way to make them
         | infinitely worse...
        
       | danellis wrote:
       | If you're going to invoke these operations from JavaScript, why
       | on earth would you still want to control them using command-line
       | style switches? Reproducing the functionality: fine, useful.
       | Reproducing the interface: inelegant and probably error-prone.
        
         | anonydsfsfs wrote:
         | According to the README, the goal of this project is to
         | "eliminate your shell script's dependency on Unix while still
         | keeping its familiar and powerful commands". Changing the
         | interface would add an unnecessary learning curve, since the
         | target audience is already familiar with the conventional
         | command-line style switches.
        
       | smilekzs wrote:
       | I know this has been around for quite a while but I feel obliged
       | to point out one major use for this: Embedding portable one-
       | liners in the `package.json` file invoked through `npm run` [1],
       | because you cannot assume from which shell is `npm` called by
       | users of your package.
       | 
       | [1]: https://docs.npmjs.com/cli/v7/commands/npm-run-script
        
       | 0mp wrote:
       | There is also Modernish, which is a library for writing portable
       | shell scripts and it seems to support all kinds of different
       | versions of shells across a variety of operating systems. It
       | really takes care of all the quirks and bugs every platform has.
       | 
       | https://github.com/modernish/modernish
        
       | statico wrote:
       | ShellJS was a delight to use when we had to build a cross
       | platform Electron-based (sorry) desktop application for Mac and
       | Windows. It replaced batch and shell scripts, async operations
       | were easy thanks to NodeJS, and the scripts were maintainable.
       | 8/10, would use again.
        
         | nerdponx wrote:
         | I feel like Node being "async-first" is such an underrated
         | feature, compared to its big competitors (Python, Ruby, Perl).
         | I really don't some of the Javascript quirks, but Node is a
         | great general-purpose scripting tool as a change of pace from
         | Python.
         | 
         | Edit: I know we're not supposed to talk about voting on HN, but
         | really? -2 for saying "hey maybe NodeJS is actually kind of OK
         | for some stuff" is wild.
        
           | hamburglar wrote:
           | Except the first two commands I looked at the implementation
           | for were implemented as sync IO calls (and one of them was
           | "cat" which is implemented as a sync read of the entire
           | file).
        
           | VWWHFSfQ wrote:
           | I don't think "async-first" is really all it's cracked up to
           | be. It's great for concurrent I/O (webservers). Not great for
           | writing run-of-the-mill sysadmin scripts like rotating log
           | files, doing file backups, etc. Now instead of just knowing
           | that your cron job is doing something one at a time, suddenly
           | you have all these async things happening and you look at
           | your process table and there's 40 node.js processes trying to
           | compress every log file in the system all at once.
           | 
           | And if you don't want it to do that then you have to start
           | managing the concurrency yourself. I've never had to manage
           | concurrency in a shell script beyond just making sure my
           | crons don't run over each other if they take too long.
        
             | nwienert wrote:
             | You're conflating concurrency and parallelism. Unless
             | you're explicitly forking the process, the async all
             | happens in one process.
             | 
             | Async is incredibly easy to manage in node, even the
             | simplest linter handles telling you you're forgetting to
             | await if you are.
        
         | an_opabinia wrote:
         | One thing I wish Windows developers did more was bundle
         | Busybox, a 1.6mb binary, to run shell scripts with bashisms,
         | rather than use batch files, powershell or other alternatives.
         | 
         | If Microsoft had only put all the PowerShell for Linux
         | resources into Busybox.
         | 
         | MSYS2 is also pretty comfy. But that audience is probably
         | better served by running WSL2.
        
           | VWWHFSfQ wrote:
           | This reminds me of a web hosting/managed colocation company I
           | worked for back in the early 2000s. They pretty much only had
           | unix sysadmins so basically every windows box got cygwin and
           | activestate perl because it was really the only thing these
           | guys knew how to use. Nobody ever bothered to learn how to
           | script a windows machine. PowerShell was still in its
           | infancy. But nowadays I don't think it's really appropriate
           | to not use the platform-native tools to administer the
           | machine.
           | 
           | Imagine installing windows powershell on debian because you
           | don't know how to write unix shell scripts.
        
             | an_opabinia wrote:
             | PowerShell is so bad though, absolutely zero people do
             | that. PowerShell for Linux is a straight up butt of jokes
             | at Microsoft for having zero DAU.
        
       | suifbwish wrote:
       | Is it really that difficult to just update a database value to
       | trigger action by a listening process that checks for that value
       | on a short time interval? No extra libraries needed and the shell
       | and web server world remain completely separate.
        
       | nodesocket wrote:
       | I believe Google just released https://github.com/google/zx. I am
       | looking to refactor some gnarly and unreadable bash scripts in
       | JavaScirpt and wondering what everybody thinks is the best
       | option?
       | 
       | Biggest pain points in pure bash is flow control, string
       | manipulation, arrays, and looping.
        
       ___________________________________________________________________
       (page generated 2021-05-09 23:00 UTC)