Any recommendations on how to run this, eval $(minikube docker-env) using shell eval is not available, the command basically gives you 4 export commands to run, so I could grab the content of "minikube docker-env" and run it another way but the main goal is to get the exports run before running a docker command, so it all needs to be inside the same context
If you want to evaluate some bash/zsh/whatever you need to do it in the context of a bash/zsh/whatever shell. e.g.:
(shell "bash" "-c" "eval $(minikube docker-env); whatever-else")okay thanks I did consider that, but was equally curious if there was a way to run a series of command inside a context which you have setup
I have no idea what you have in mind
you could possibly open a bash shell and iteratively feed it with more input I guess
yeah, it was more a question if you could create a perhaps bash shell keep the state and send additional commands after each had completed
I will go with the bash -c option, as its a quick script
(require '[babashka.process :as p])
(def bash-process (p/process {:out :inherit} "bash"))
(def input (io/writer (:in bash-process)))
(binding [*out* input]
(println "export FOO=BAR"))
(Thread/sleep 1000)
(binding [*out* input]
(println "echo $FOO"))Another alternative is to let Babashka communicate shell commands that should be evaluated back to the bash process. I did that for a Babashka script that can change the current directory. Details here: https://github.com/teodorlu/shed/tree/429e7d8c9d1ea19588f27e116a3bedf60aa314d9/contrib/clonecd
with_shelleval is a bash function that runs something. If that something puts !SHELLEVAL echo haha on stdout, you'll see haha printed.
You can also change directories, set environment variables, etc.
I've done a similar thing here once: https://stackoverflow.com/a/64804398/6264
okay thanks both for the options, give me some things to try 🙂
I need to run a simple babashka script as an AWS Lambda. Is holy-lambda the recommended approach these days?
there's also #blambda - https://github.com/jmglov/blambda
it's also relatively easy to use nbb (or squint, or whatever JS thing) for lambda: https://github.com/babashka/nbb/blob/main/doc/aws_lambda.md
Thanks for the pointers. Will check out those options. Blambda looks like a turnkey solution.
Following up from a thread elsewhere: @borkdude Re: bb -- do you use build.clj as well? Or would you just use bb tasks?
@seancorfield re: https://clojurians.slack.com/archives/C03RZGPG3/p1753123313702819?thread_ts=1753122112.128639&cid=C03RZGPG3
yes, I definitely use build.clj but just for what it says it does: building stuff. I often have a bb task called deploy that deploys stuff by invoking clj -T:build deploy for example
I'm kinda curious where you draw that line?
At work, our build.clj is about 400 lines as I recall and does a lot of stuff, including running various tasks as subprocesses, and our "usual" way to work with it is to start a REPL with -M -i build.clj -r essentially, so we don't pay the startup cost for every task.
I don't invoke clj -T:build for REPL stuff, I just start a REPL by what I usually call bb dev
for example, here is the bb dev task for clerk:
https://github.com/nextjournal/clerk/blob/149c4e5aeaaefb18ddaeae381595a3b5f7918481/bb.edn#L174
Okay, so I guess your bb dev is our dev.sh build at work, which in turn is:
cd $folder && clj $force -M:allow-attach-self:build -i bases/build/src/ws/build.clj -e "(in-ns 'ws.build)" -r
🙂yes, bb dev could also just be (shell "script/dev.sh") ;)
invoking scripts in a certain directory is also a fine solution which comes close to a task runner. but sometimes it can be confusing which scripts are intended for that or not, for newcomers. bb tasks just gives you an overview of the most important things you'd invoke you in your project.
Are the tasks that start with - some sort of "private" that isn't listed when you ask bb what tasks are available?
yes. invoking bb tasks from the command line will give you a clean overview of all the important tasks, without the "helper" tasks which start with a -
In that clerk task file, several nses are required with an alias but not used, e.g., babashka.process :as p -- but shell (and clojure) are used without an alias. Is that require needed?
(as I'm reading this, I'm try to think about whether I could coalesce my testing scripts for next.jdbc since I have a bb script to run multi-version testing from the command line and similar code in my build.clj file for running tests as part of CI build & deploy).
I sort of expected babashka.process to have a clojure function...
shell and clojure are the only automatically refer-ed things since you need them often. they come from a special namespace called babashka.tasks
the rest of the stuff works like normal bb scripting.
Most of this stuff should be documented here: https://book.babashka.org/#tasks
I don't mean this as a RTFM, feel free to ask anything you want
Specifically, I'd like to be able to reuse the multi-version testing code between https://github.com/seancorfield/next-jdbc/blob/develop/run-tests.clj and https://github.com/seancorfield/next-jdbc/blob/develop/build.clj#L24-L38
(the latter uses tools.build for java process invocation but could happily shell out to clojure instead really)
clojure uses the deps.clj clojure runner. if you prefer to run your system-installed clojure, all you need is shell basically
I like the succinctness of bb tasks as a dev front end and have them abstract any clojure -T:build... invocations.
@lee Hmm, so instead of me thinking about trying to reuse code between bb and build.clj, turn it on its head and use bb as the "interface" and have it shell out to clojure -T:build as needed...? Might be an interesting exercise for me to try on next.jdbc...
I sometimes (not always) share code between bb and build.clj if it's convenient to have some of the code run in both.
but to get started, you could just use bb tasks as a simple "front-end" like lread suggested
if you're going to be using bb tasks, make sure to install the completions, I find those very handy: https://book.babashka.org/#_terminal_tab_completion (more advanced completion scripts are on the wiki, I use the one in the book)
If you have a folder that matches a task name, that seems to offer the folder (with a trailing /) -- is that expected?
(for bash)
(!2006)-> bb tasks
The following tasks are available:
test Run the test suite.
ci Run the CI pipeline of tests and build the JAR.
(2025-07-21.15:26:40)-(~/oss/next-jdbc)
(!2007)-> bb t
target/ test/ probably not. it does auto-complete files because you can invoke files with bb too, but directories should probably be filtered out
If I change my test task to tests then I get this:
(!2010)-> bb t
target/ test/ tests weird. did you restart your shell, maybe that helps?
ah yes, tests is what you should see, sorry I didn't catch that
sometimes you have multiple test tasks. it's a convention in bb tasks to write those as test:cljs and test:clj for example. auto-completion is handy for those cases where you have typed bb test:
But if my task is test and I have a folder called test, I won't see the test task right now?
http://claude.ai suggests these improvements: https://claude.ai/share/4bcb813e-6e56-436a-a075-4e889e1b40b5 if you can test either, happy to update the book 😆
zsh 😞
you are using bash I guess?
Yup.
_bb_tasks() {
COMPREPLY=( $(compgen -W "$(bb tasks |tail -n +3 |cut -f1 -d ' ')" -- ${COMP_WORDS[COMP_CWORD]}) );
}
# autocomplete filenames but not directories
complete -f -o filenames -F _bb_tasks bbThanks!
does it work?
Nope.
Still get the folder.
ok, I'll take a look at this when I have more time. thanks for reporting. I'll come back to this
For now I ended up with this, which at least doesn't put the / on folders (and doesn't add a space after a match):
_bb_tasks_and_filenames() {
COMPREPLY=(
$(
compgen -W "$(bb tasks |tail -n +3 |cut -f1 -d ' ')" -- ${COMP_WORDS[COMP_CWORD]};
compgen -f -- ${COMP_WORDS[COMP_CWORD]}
)
);
}
# autocomplete filenames as well
complete -o nospace -F _bb_tasks_and_filenames bbThere's more stuff here: https://github.com/babashka/babashka/wiki/Shell-completion
Maybe one reason for completing also directories was that there may be scripts in directories
but good that you found your tweak
It won't auto-complete task names with : in for some reason but I'll circle back to that later.
next.jdbc PR to switch to using bb tasks -- build.clj only handles building & deploying the JAR now; bb.edn has the multi-version / JDK test logic (you have to tell it what JDK you are using, for now): https://github.com/seancorfield/next-jdbc/pull/305
Nice! If you don't like the big chunk of clojure code in your bb.edn you can still put it in a file and have the task be (load-file "whatever.clj")
Or put it on the bb classpath with for example:
{:paths ["bb"]}
and execute it as a normal function in a task. All up to you of courseWell, I already had nearly all of that "big chunk of clojure code" in run-tests.clj 🙂
But run-tests.clj is gone now (moved to bb.edn essentially). The duplication of the env vars is gone (from the GH Actions files). The duplication of the multi-version testing is gone (from build.clj). So that's all a win.
Several back and forths with Claude 4 Sonnet on the : completion got me this:
# Remove any existing bb completion first
complete -r bb 2>/dev/null || true
_bb_complete() {
local cur tasks
# Extract what we're trying to complete (everything after 'bb ')
cur="${COMP_LINE#*bb }"
[[ "$cur" == "$COMP_LINE" ]] && cur="" # Handle case with no space after bb
# Get available tasks
tasks=$(bb tasks 2>/dev/null | tail -n +3 | cut -f1 -d ' ')
if [[ "$cur" == *:* ]]; then
# For colon completions, return only the suffix after the colon
local prefix="${cur%:*}:"
COMPREPLY=($(compgen -W "$tasks" -- "$cur" | sed "s/^$prefix//"))
else
# Normal completion
COMPREPLY=($(compgen -W "$tasks" -f -- "$cur"))
fi
}
complete -o nospace -F _bb_complete bb(the first "solution" was horrendously complex so this is Claude's "simpler" version -- and it seems to work perfectly)
@borkdude you said in the just thread that bb can do tasks in parallel. that's cool. how does that work? what's the use-case? i don't do a lot of stuff that would benefit from parallel execution so i'm unfamiliar
the use case is for example spinning up a shadow-cljs build along with a JVM Clojure REPL. bb dev can do both of those, so you can start "development"
that's clever!
how does it handle closing down both? i usually have two terminal windows split
just press ctrl-c to close both
parallel tasks are very neat for monorepos for builds/compiling too: https://github.com/bob-cd/bob/blob/main/bb.edn#L47 has significant speedups