Fork me on GitHub

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?


Perfect, thank you!


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 ( "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'")
     (map (fn [slug] {:slug slug})))


thank you!

🙌 1

@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 for how to cdwith it


nm. I see borkdude answered but recommmend the wiki page for the bashisms


@U08ALHZ2N I appreciate that! I thought I’d seen that before but couldn’t find it

😃 1

@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


or a clojure process: (clojure {:dir "foo"} "-M:bar")

Charlot Shaw21:08:40

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?

borkdude21:08:20 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 ?



💯 1
❤️ 1
Charlot Shaw21:08:15

Exactly my next question, thank you.

Charlot Shaw21:08:25

This would likely be a good addition to the docs


If you have a good suggestion how to make that clearer, feel free to submit PRs

Charlot Shaw21:08:50

Sure, will do.


Woohoo, 1000 members in this channel. A milestone! Unfortunately I can't see who it was, but thanks!

Charlot Shaw21:08:20

Actually, that was me.

Charlot Shaw21:08:27

I joined to ask this question

Charlot Shaw21:08:47

Biggest Kiriban I’ve been in so far.


I can send you free stickers as a reward ;)

Charlot Shaw21:08:31

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

Charlot Shaw21:08:31

No worries, surprise free stickers at any pace is lovely.