This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-18
Channels
- # announcements (2)
- # babashka (65)
- # beginners (104)
- # boot (8)
- # calva (23)
- # circleci (3)
- # clj-commons (1)
- # clj-on-windows (3)
- # clojure (43)
- # clojure-europe (45)
- # clojure-france (2)
- # clojure-italy (3)
- # clojure-nl (3)
- # clojure-norway (13)
- # clojure-uk (4)
- # clojurescript (5)
- # core-typed (2)
- # cursive (5)
- # data-science (2)
- # datalevin (10)
- # emacs (38)
- # events (2)
- # fulcro (11)
- # graphql (6)
- # gratitude (2)
- # helix (11)
- # hugsql (3)
- # jobs (2)
- # lsp (17)
- # luminus (1)
- # malli (15)
- # missionary (3)
- # nrepl (6)
- # off-topic (6)
- # pedestal (2)
- # portal (16)
- # reagent (33)
- # reitit (4)
- # releases (12)
- # ring (2)
- # sci (3)
- # shadow-cljs (21)
- # spacemacs (7)
- # sql (5)
- # tools-build (36)
- # web-security (2)
Is there a way to export environment variables in babashka?
I'm trying to replace a bash script that that performs some curl requests and puts the result in a environment variable.
so blah.sh
contains
export BLAH=$(curl )
then I call source blah.sh
ah I see!
yeah, you cannot alter the bash environment from an invoked program, this is why you need source
and this is no different with bb.
so you can do:
(println (str "export BLAH=" the-value))
and then source the printed result with bash.
Alternatively you can launch a new shell with that environment variable set:
(babashka.tasks/shell {:extra-env {"BLAH" the-value}} "bash")
$ bb -e '(babashka.tasks/shell {:extra-env {"BLAH" "dude"}} "bash")'
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit .
bash-3.2$ echo $BLAH
dude
bash-3.2$ exit
exit
Ah, thank you!
Is there something ready to be used under babashka tasks with a grep find replace a specific word so it could be for example replacing all the namespace by the user's one?
for example in my specific case i can just leave a src working wth a dummy namespace as a template, and the user can just change it using bb as its convenience.
@U1ZJ06MMK I recommend using (str/replace s "{{namespace}}" namespace)
where s
is (slurp "some-file.clj")
if you want more advanced templating you can use selmer
which is included in babashka
thanks for the guidance. i think i am very close to solve it. thanks again michael!
I want to use babashka tasks in CI pipelinne for clojure deps.edn projects. Now what I don't know is how to use the same scripts in multiple projects. I was thinking to publish a git gist and then somehow load them and execute them. Or perhaps put them into a jar? Can bababshka use any jar?
You can put your scripts in a library and then refer to those libraries using :local/root
Load file will not work because I have multiple GitHub repos. I want to share between all of them.
I do this for example with my github upload code. https://github.com/borkdude/gh-release-artifact
Used here: https://github.com/clj-kondo/clj-kondo/blob/2ada495072b6bf10bef12a759ac2cf879fc0d734/bb.edn#L4
So let's take a simple example: in all my projects I want to call cljfmt, with some cljfmt settings that I like.
are you paying attention to what I said before? I feel like we're talking past each other. you can use a git library
All good. Your bb.edn exports tasks from a git dependency. That's all I need. It was so obvious that I missed it at first. Thanks @U04V15CAJ
Ah well, it doesn't export tasks from a git dependency, but it imports functions from a git dependency which you can use within tasks.
{:outdated {:extra-deps {com.github.liquidz/antq {:mvn/version "RELEASE"}} :main-opts ["-m" "antq.core"]} }
which would be ok, but then I have a big string in the ocnfig. It would ail when things are more complex.
@hoertlehner why don't you put that :outdated stuff in deps.edn?
:lint {:extra-deps {clj-kondo/clj-kondo {:mvn/version "RELEASE"}} :main-opts ["-m" "clj-kondo.main" "--fail-level" "error" "--lint" "--config" "cljkondo.edn"]}
@hoertlehner I think you can just add "-Sdeps" '{:deps ...}
Example:
{:tasks
{clj-kondo (clojure "-Sdeps" '{:deps {clj-kondo/clj-kondo {:mvn/version "2021.10.19"}}}
"-M" "-m" "clj-kondo.main" "--lint" "src")}}
very stupid question: is there a babashka function to change the directory? It seems "cd" is not a binary, but a bash command. So I dont want to assume the user has bash, but stay in babashkas world.
@hoertlehner the working directory is immutable in the JVM / babashka. You can pass :dir "foo"
to several task commands like shell
and clojure
. E.g.:
(shell {:dir "subproject"} "ls")