[HN Gopher] Shh: Simple Shell Scripting from Haskell
___________________________________________________________________
Shh: Simple Shell Scripting from Haskell
Author : subset
Score : 167 points
Date : 2023-11-25 12:22 UTC (10 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| cole-k wrote:
| Those of you who use (or used) this as your shell: care to share
| your experience?
|
| It seems a lot less full-featured than https://xon.sh/, but maybe
| you don't need a lot of bells and whistles for regular usage. I
| mostly run build, execute, and install commands.
|
| I'm somewhat enticed at the possibility of being able to wrap
| common executables into forms that are typed (like nushell or
| elvish) and manipulate them in a way that leverages the type
| checker.
| themk wrote:
| Author here. I rarely use it as a shell personally, though it
| does work, and sometimes I drop into it for the odd task. It's
| primarily designed to replace overgrown bash scripts.
| fuzztester wrote:
| Related: has anyone tried scheme shell (scsh) and what is your
| experiences with it?
|
| https://en.m.wikipedia.org/wiki/Scsh
| loevborg wrote:
| Last time I tried I couldn't get it to compile
|
| These days https://babashka.org/ is a much better option. It's
| powerful, fast, modern, works everywhere and has effortless
| multitasking.
| elviejo wrote:
| There is also Rash: Racket Shell that looks super interesting.
|
| https://youtu.be/yXcwK3XNU3Y?si=XuABEBZReyfhraAh
|
| Haven't tried it though.
| velcrovan wrote:
| It is interesting, but not something you'd really want to
| rely on. (see the issues, comments and commit history:
| https://github.com/willghatch/racket-rash)
|
| This project could really benefit from picking up a couple of
| steady contributors. It looks like the author is a new dad,
| and his commit history looks about like what mine did at that
| stage.
| forgotpwd16 wrote:
| Interestingly Rash is also suitable as a user-oriented shell
| (like bash) rather be reserved for scripting (like scsh).
| chubot wrote:
| FWIW there is a big list of similar libraries / internal DSLs
| in nearly all Lisps, and nearly all statically typed functional
| languages here:
|
| https://github.com/oilshell/oil/wiki/Internal-DSLs-for-Shell
|
| e.g. points to another Haskell project, which may be old -
| https://github.com/jgoerzen/hsh/wiki
|
| Which is related to the list of free-standing shells:
|
| https://github.com/oilshell/oil/wiki/Alternative-Shells
| agumonkey wrote:
| Not this one, but for a while I tried getting
|
| https://wryun.github.io/es-shell/
|
| to run (a functionalish shell)
| nemoniac wrote:
| IMHO it's worth spending some time getting acquainted with it.
| It's very clearly thought out conceptually with good separation
| of concerns. I learned a lot about Scheme and a lot about Unix
| from using it.
| fuzztester wrote:
| Thanks for the answers, guys.
| adastra22 wrote:
| "Shell scripts" is kinda the domain of newLISP, which I've used
| before and like.
| ekiauhce wrote:
| You can't really move away from bash, unless there would be
| alternative as widely available on different Unix systems as bash
| is.
|
| Yes, you came up with a nice syntax for your Haskell scripts, but
| what it cost to install all required dependencies on, for
| example, newly created Ubuntu server?
| pbiggar wrote:
| We're trying to do a similar thing with darklang right now:
| providing a single binary with a built-in package manager. The
| idea being making it easy to write readable "bash" scripts
| (including writing them with AI), but with just one dependency
| - the darklang binary itself.
| themk wrote:
| Yep, this is mainly used for turning those bash scripts that
| you let get too large into a real program. You port your
| script, basically line for line, into this, and then start
| chipping away at it until you have something less scary.
| forgotpwd16 wrote:
| Too bad Hugs98 (installation is few MBs) is no longer updated
| leaving only GHC (GB+).
| maleldil wrote:
| You don't need the compiler to run the program in production.
| You only need the binary. I'd argue that a heavy toolchain in
| the dev machine isn't a big deal.
| IshKebab wrote:
| Bash scripts tend to be used in situations where you want
| to edit them and not have to deal with a recompilation
| step, let alone a multi-GB compiler install. That seems
| like a deal-breaker to me.
|
| The best alternative I've found so far is Deno. It natively
| supports single file scripts _with third party
| dependencies_ (this is a big issue with replacing Bash with
| Python). It uses an existing popular language (so now
| "learn our weird language" problem). Installation is very
| easy.
|
| The only real downside I've found is this stupid bug that
| they refused to fix:
|
| https://github.com/denoland/deno/issues/16466
| ReleaseCandidat wrote:
| Yes, but Shh works on Windows. And on OS X you need to install
| about the same things if you want to have a recent Bash
| > /bin/bash --version GNU bash, version
| 3.2.57(1)-release (arm64-apple-darwin23) Copyright (C)
| 2007 Free Software Foundation, Inc.
| keybored wrote:
| You're not always working in crummy environments. Sometimes you
| can have nice things (if you think this is nice).
|
| I don't get the impression that this is supposed to be the
| final solution to Bash.
| marcosdumay wrote:
| Why do you want to develop Haskell programs in a newly created
| Ubuntu server? Or do you want to compile it down at the
| deployment target?
| norir wrote:
| > You can't really move away from bash, unless there would be
| alternative as widely available on different Unix systems as
| bash is.
|
| Lua can be built from source in a few seconds on just about any
| system and can be used pretty easily as a bash replacement. You
| can even bundle the lua script in a bash script that
| idempotently installs lua and then calls the lua script
| embedded in heredoc.
| tikhonj wrote:
| It's pretty easy if you use NixOS :)
|
| That's been one of the somewhat unexpected benefits for me with
| NixOS: it's so easy to pull in tools and libraries that I don't
| have to worry about using less popular options.
| themk wrote:
| Author here.
|
| My main use for this is incremental migration away from bash. I'm
| not saying this is the best way to do scripts, but it's a pretty
| great stepping stone. Just following the cargo culting guide [0]
| can already uplift a bash script without changing the logic too
| much. From there you can start adding structure.
|
| My secondary use case is little scripts in NixOS/nixpkgs. There
| are some helpers in there that make it quite convenient.
|
| [0] https://github.com/luke-
| clifton/shh/blob/master/docs/porting...
| sshine wrote:
| shh is a really cool package, and so is turtle and shelly:
|
| https://hackage.haskell.org/package/turtle/docs/Turtle-Tutor...
|
| https://hackage.haskell.org/package/shelly
|
| shh's "Alternatives" section summarises nicely some of the
| differences between these:
|
| https://github.com/luke-clifton/shh#alternatives
|
| shh has a neat [fmt| ... |] macro that gets you around escaping
| strings.
|
| shh generally has more Template Haskell support; you may or may
| not like this.
|
| I am personally leaning towards shh because of its "native pipe
| style".
| ben0x539 wrote:
| This seems fun! Far too few people who are all "your bash scripts
| shouldn't be 300 lines and have complex logic!" address why
| people reach for bash scripts in the first place, so kudos for
| that.
| williamcotton wrote:
| Huh, I was just tinkering with the same sort of thing with the
| same motivations but with F#:
|
| https://github.com/williamcotton/fs_playground/blob/main/Scr...
|
| Thanks for this, I'm going to borrow a lot of your concepts,
| especially the added infix operators, those are slick!
___________________________________________________________________
(page generated 2023-11-25 23:00 UTC)