This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-01
Channels
- # announcements (53)
- # babashka (27)
- # beginners (103)
- # biff (1)
- # calva (21)
- # cider (5)
- # circleci (12)
- # clj-kondo (7)
- # cljfx (3)
- # cljsrn (9)
- # clojure (25)
- # clojure-europe (21)
- # clojure-nl (1)
- # clojure-uk (21)
- # clojured (1)
- # clojurescript (49)
- # cursive (20)
- # datomic (33)
- # events (3)
- # fulcro (39)
- # graalvm (20)
- # graphql (2)
- # introduce-yourself (1)
- # jobs (14)
- # keechma (3)
- # lsp (34)
- # malli (18)
- # meander (15)
- # off-topic (30)
- # polylith (10)
- # re-frame (21)
- # releases (2)
- # remote-jobs (5)
- # sci (10)
- # shadow-cljs (16)
- # tools-deps (2)
- # vim (6)
Thank again for the help yesterday, I did a bit more digging... I am not sure if this is an issue or not?
Say I have two scripts:
<dir>/foo
<dir>/bar
bar
contains:
#!/usr/bin/env bb
(ns bar)
(defn hello [] (println "test"))
foo
this works load-file
before ns
#!/usr/bin/env bb
(require '[babashka.fs :as fs])
(load-file (str (fs/parent *file*) "/bar"))
(ns foo)
(when (= *file* (System/getProperty "babashka.file"))
(bar/hello))
foo
this doesn't work
#!/usr/bin/env bb
(ns foo
(:require [babashka.fs :as fs]))
(when (= *file* (System/getProperty "babashka.file"))
(load-file (str (fs/parent *file*) "/bar"))
(bar/hello))
7: (bar/hello))
^--- Could not resolve symbol: bar/hello
For now I am just going to use preload to load them all, but was hoping of explicitly loading some scripts
This is normal behavior, you will get this with JVM Clojure as well. Itβs called the Gilardi scenario. https://technomancy.us/143
As I explained before you probably want to be using add-classpath + require for this
@U015Y1A1N8Y Here is an example: /tmp/script/foo.clj:
(ns foo
(:require [babashka.classpath :refer [add-classpath]]
[babashka.fs :as fs]))
(add-classpath (str (fs/parent *file*)))
(require '[bar :as bar])
(prn (bar/bar-fn))
/tmp/script/bar.clj:
(ns bar)
(defn bar-fn []
:bar)
$ bb /tmp/script/foo.clj
:bar
@U8QBZBHGD omg! Thank you so much for spending so much time and sending so many examples across π @U04V15CAJ great thank you for the article! I really was wondering as to they why this wasn't working.
Pomodoro timer in babashka: https://github.com/babashka/babashka/discussions/910
What would this look like in Tasks?
bb -cp $(clojure -Spath -Aremove-clojure) --uberscript data-loader -m append-hash
@bocaj you don't have to set the classpath anymore if you have a bb.edn
, also the remove-clojure thing is done automatically
It doesn't do everything sed
does, but it should work in the most common cases as a substitute for s/something/somethingelse//
I think the easiest way would be to (-> (slurp "file") (clojure.string/replace #"foo" "bar") (spit "file"))
yes, I agree with what @UFDRD93RR wrote, just slurp, str/replace and spit. you could also use Selmer if you need templating.
Is there a convenient way to pre-pend #!/usr/bin/env bb
to for example the output file from uberscript. Related to sed, above, thinking concat
with spit and slurp
The reason it does not do this by default is that it's not cross platform. To do this using a Clojure expression, you can do:
(spit "uberscript.clj" (str "#!/usr/bin/env bb\n\n" (slurp "uberscript.clj")))
you can probably optimize that using some streaming solution if needed, but in a lot of cases this does the job fine ;)
Adam is playing around with babashka and scittle on his stream now: https://www.twitch.tv/adam_james_tv