Fork me on GitHub
#babashka
<
2020-03-20
>
jpettersson07:03:35

At http://ekspono.com we're rewriting our monorepo tooling from bash to babashka and it's a huge productivity boost! Thanks for a great tool @borkdude!

🎉 12
borkdude16:03:45

nice, I didn't know this, but you can detect if stdin is available or not, without reading it:

$ ./bb '(.available System/in)'
0
$ echo 1 | ./bb '(.available System/in)'
2

😁 4
borkdude16:03:01

(this only works in the upcoming version)

eval-on-point16:03:19

Yesterday I got babashka up with the inf-clojure repl and had a great experience writing a script. Wondering now if it is worth it to make a Spacemacs layer for inf-clojure or if cider support for socket repls is soon coming

mauricio.szabo16:03:55

If you are not too hooked on EMACS, you can try Chlorine on Atom. It have first-class support for bb 🙂

eval-on-point16:03:20

Thanks for the tip! I'll definitely check it out next time I have a task for bb.

mauricio.szabo21:03:56

Also, if you have any trouble or want to add any feature to it, you can check out the #chlorine channel.

borkdude16:03:11

I think inf-clojure is specifically designed for lesser sophisticated REPLs like socket REPLs. Might be good to ask @bozhidar about this.

hairfire16:03:28

Anyone know how to execute 'kaocha --watch' from within a babashka script?

borkdude16:03:58

@hairfire (require '[clojure.java.shell :refer [sh]]) (sh "kaocha" "--watch")

hairfire16:03:50

When I do that, I never see any output from kaocha

borkdude16:03:16

@hairfire Ah, we got a solution for that too. just a moment

eval-on-point16:03:26

I did a little browsing of cider's roadmap and socket repl support is on there. Can't speak to their progress towards it, though

borkdude16:03:33

@hairfire Something like this might do it:

(ns process-builder.example
  (:import [java.lang ProcessBuilder$Redirect]))

(defn- shell-command
  ([args] (shell-command args nil))
  ([args {:keys [:throw?]
          :or {throw? true}}]
   (let [pb (let [pb (ProcessBuilder. ^java.util.List args)]
              (doto pb
                (.redirectInput ProcessBuilder$Redirect/INHERIT)
                (.redirectOutput ProcessBuilder$Redirect/INHERIT)
                (.redirectError ProcessBuilder$Redirect/INHERIT)))
         proc (.start pb)
         exit-code (.waitFor proc)]
     (when (and throw?
                (not (zero? exit-code)))
       (throw (ex-info "Got non-zero exit code" {:status exit-code})))
     {:exit exit-code})))

(shell-command ["kaocha --watch"])

babashka 4
bananadance 4
hairfire16:03:47

I'll give it a try

borkdude16:03:56

(.redirectOutput ProcessBuilder$Redirect/INHERIT)
is the essential part

nate16:03:14

I used something similar in a script to launch a clojure repl

borkdude16:03:02

yeah. this is also used in deps.clj to start the REPL: https://github.com/borkdude/deps.clj

hairfire16:03:09

Hey @borkdude and @nate I get "clojure.lang.ExceptionInfo: Cannot run program "kaocha --watch": error=2, No such file or directory ..." I assume it is because I have kaocha on my path, but not in a system location like "/usr/local/bin". Thoughts?

nate16:03:15

oh interesting

nate16:03:44

is there a property in java that indicates what PATH it uses? maybe that's not the same as in the shell

borkdude16:03:53

(System/getenv "PATH")

borkdude16:03:30

@hairfire you have to write ["kaocha" "--watch"], not ["kaocha --watch"], just to make sure

nate16:03:50

oh yes, need to split it up

hairfire17:03:35

FANTASTIC!!! IT WORKS 😀 I REALLY like babashka. I'm trying to encourage the use of "Clojure" for any and all development activities done by my team, and babashka is another tool I can point to.

hairfire17:03:36

Can/Should "shell-command" be somehow part of babashka?

borkdude17:03:15

Maybe at some point, but not right now. I've had variations of this in different scripts and each script seemed to need something new, so I'm a little bit erring on the side of "make your own". E.g. some scripts want redirect output, others don't, and handling all these options becomes complex and there's always one situation where you need to drop down into the ProcessBuilder interop

borkdude17:03:33

I've made this issue to add some more docs around it: https://github.com/borkdude/babashka/issues/299

hairfire17:03:10

Got it @borkdude, thanks again, and keep up the GREAT work!

borkdude17:03:28

You can put it in a babashka library or put it in BABASHKA_PRELOADS or use load-file for your company wide babashka helpers

borkdude23:03:38

babashka v0.0.77: adds supports for transit, can now run the tolitius/cprop config lib, several other fixes and enhancements. https://github.com/borkdude/babashka/releases/tag/v0.0.77