Fork me on GitHub

Humm... Is there a simple (easy) way to execute babashka scripts off of github? aka something like

#!/usr/bin/env bb
(add-classpath "")  ;; has project "myutility" with src/mynamespace.clj
(require '[mynamespace])
(mynamspace/main *command-line-args* )
perhaps using bb.edn so I can pull in dependencies as needed too... sort of like clojure's
clojure -Sdeps '{:deps {cljfmt {:mvn/version "0.8.0"}}}' -m cljfmt.main myInputFile 
but for bb.... and github...

Bob B04:08:45

The short(ish) answer is yes, assuming you have a deps.edn file in your repo. In the same way that you can specify git deps for clj, you can do it either in bb.edn or using babashka.deps:

(ns something
  (:require [babashka.deps :as deps]))

(deps/add-deps '{:deps {io.github.bobisageek/bb-test-thing
                             {:git/url ""
                              :sha "5a7eb8fb71665cbee2c6d5c90c38ea9fda48f7a6"}}})

(require '[io.github.bobisageek.stuff :as s])


Bob B04:08:14

... please ignore the ugliness of the code - I just threw the repo up there for a really simple repro


☝️ you can also look at the repos I posted three messages above that used git deps in a bb.edn file

John Conti21:05:58

I followed this recipe but the dependency resolution either didn't work or I didn't use it properly:

#!/usr/bin/env bb
(ns fmt-check
  (:require [babashka.deps :as deps]))
(deps/add-deps '{:deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}})
(require '[cljfmt.main :as cljfmt])
(apply cljfmt/-main *command-line-args*)

John Conti21:05:32

% ./fmt-check
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: difflib.DiffUtils
Location: cljfmt/diff.clj:2:3

----- Context ------------------------------------------------------------------
1: (ns cljfmt.diff
2:   (:import [difflib DiffUtils]
     ^--- Unable to resolve classname: difflib.DiffUtils
3:            [ File]
4:            [java.util.regex Pattern])
5:   (:require [ :as io]
6:             [clojure.string :as str]))

----- Stack trace --------------------------------------------------------------
cljfmt.diff - cljfmt/diff.clj:2:3
cljfmt.main - cljfmt/main.clj:3:3
fmt-check   - /Users/jconti/code/reifyhealth/fine-grained-authorization/./fmt-check:5:1

John Conti21:05:48

But Clojure resolves the deps and is able to run:

% clojure -Sdeps '{:deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}}' -m cljfmt.main
WARNING: Implicit use of clojure.main with options is deprecated, use -M
      --file-pattern FILE_PATTERN                  \.clj[csx]?$
      --indents INDENTS_PATH
      --alias-map ALIAS_MAP_PATH
      --project-root PROJECT_ROOT                  .


Can I make the bb repl share the same environment with current shell? eg When I export AWS_SECRET_ACCESS_KEY="5beQdsugRmMy1" I'd like the bb repl to be aware of it.


export FOO=1 bb repl ?


This'd mean I have to restart the repl every time I change the variables. I am looking for a more scalable option @borkdude


Unfortunately the JVM doesn't let you change environment variables within the same process, this also applies to bb


You can however spawn new processes from within bb with env vars


Is there a way to 'persist' the process environment, so that i can issue repl functions calls outside of the process form?


System/getenv gives you the entire map


Ok. How can I do this correctly, it fails ?

(-> (process ["export" "FOO" "1"] {:out :string}) check :out str/split-lines first)


(process [...cmd...] {:extra-env {"FOO" "1"}})


export is a bash thing. process doesn't start bash necessarily

👍 3

unless you tell it to


you can find the process docs over here:



$ bb -e '(keys (edn/read-string (:out @(babashka.process/process ["bb" "-e" "(System/getenv)"] {:out :string :err :string :env (assoc (select-keys (System/getenv) ["PATH"]) "FOO" "bar")}))))'


There is :env which replaces the environment variables and :extra-env which only adds environment variables (or replaces existing ones)


Great, thanks a lot!

Adam Stokes16:08:41

@borkdude are you worried that nbb would take away from adoption of babashka?

Adam Stokes16:08:03

I wonder if making babashka support pluggable backends would be helpful

Adam Stokes16:08:17

bb --provider=nodejs or something similar


@adam.stokes I'm not worried about that at all. bb is to Clojure JVM what nbb is to CLJS on Node.JS. A convenient fast starting environment for scripting without needed to build anything. For most things bb is sufficient, but there are sometimes situations in which a library e.g. for Excel or whatever is needed which isn't in bb, in those cases you can perhaps consider nbb.

👍 6

Also bb still remains as the only true multithreaded scripting environment across any language! babashka

💯 21