This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-15
Channels
- # architecture (5)
- # babashka (34)
- # beginners (72)
- # calva (42)
- # cherry (31)
- # cider (14)
- # clojure (27)
- # clojure-europe (11)
- # clojure-norway (17)
- # clojure-uk (1)
- # clojurescript (25)
- # community-development (13)
- # conjure (1)
- # core-async (11)
- # datascript (18)
- # datomic (11)
- # emacs (12)
- # fulcro (10)
- # integrant (5)
- # introduce-yourself (3)
- # jobs (8)
- # juxt (2)
- # malli (22)
- # off-topic (11)
- # pathom (18)
- # polylith (62)
- # rdf (18)
- # reagent (8)
- # releases (1)
- # shadow-cljs (35)
- # sql (3)
- # squint (141)
- # tools-deps (12)
- # vim (4)
- # xtdb (4)
Hi! I recall a borkdude/thanos meme posted (I think) on Twitter a while ago. Where the infinity stones were babashka/sci/nbb/... But I can't find the meme/image. Anyone got a pointer?
hey y’all, sorry if this is obvious but how do i cd
in babashka?
I use this function in most of my bb scripts:
(defn bash [cmd]
(str/trim (:out (clojure.java.shell/sh "bash" "-c" cmd))))
Then you can just write normal bash in it. cd
in a subshell works as expected:
(bash "(cd subdir && pwd)")
Another example:
(->> (bash "ls **/play.edn | sed 's|/play.edn||g'")
(str/split-lines)
(map (fn [slug] {:slug slug})))
(https://github.com/teodorlu/play.teod.eu/blob/94481a20248b3fdd70a896c8d2bc964c964d0686/play.clj#L45-L48)@nonrecursive Heyo. shell
is a handy fn to use in bb scripts as it behaves much like a line in bash would i.e. prints to stdout+ stderr and fails when a non-zero exit code occurs. See https://github.com/babashka/babashka/wiki/Bash-and-Babashka-equivalents#change-directory for how to cd
with it
@U08ALHZ2N I appreciate that! I thought I’d seen that before but couldn’t find it
@nonrecursive This is not so obvious: in a JVM-based environment, you can't change directories
If you're looking to spawn a program within a new directory, you can use (shell {:dir "foo"} "the-program")
this did the trick. thank you so much!
thank you @borkdude! yes that looks like it will work, awesome
this did the trick. thank you so much!
So, I am quite possibly missing something here. I’m trying to write a script in Babashka, and I’m wanting to do so in functional setup, IE, a bunch of functions tied together in a -main
function, instead of an imperative series of calls.
I don’t control how my script is invoked, aside from the shebang at the top of the file. Is there a way I can configure Babashka to call my main function when invoked via shebang, or do I need make a bash oneliner to pass through the command line args?
@charlot.shaw You can use (apply -main *command-line-args*)
at the bottom of your file
if you don't want to execute this, e.g. when you eval the file in the REPL, you can surround this with:
(when (= *file* (System/getProperty "babashka.file")) ...)
I've been trying to understand this too! (analogous to if __name__ == "__main__"
in python)
Am I right to assume
*file*
is the file path of the current file that's being executed
(System/getProperty "babashka.file")
is the path of the file that was invoked as "main" with eg bb script.clj
?
Exactly my next question, thank you.
This would likely be a good addition to the docs
Sure, will do.
Woohoo, 1000 members in this channel. A milestone! Unfortunately I can't see who it was, but thanks!
Actually, that was me.
I joined to ask this question
Biggest Kiriban I’ve been in so far.
I’ll not say no to free stickers. My prior laptop had all my dev stickers, but it bit it and I’ve not had the opportunity to source more.
OK, please send me your address in a DM. It will take a while since I'm leaving for a vacation tomorrow
No worries, surprise free stickers at any pace is lovely.