Fork me on GitHub
#babashka
<
2022-09-15
>
teodorlu10:09:38

I finally have a use case for using sci interpretation from within babashka! I'd like to make bink link providers more flexible. Right now, the only supported provider is :edn-file. - read EDN-formatted local file. I'd like to add a :sci-fn link provider. Draft for bink config format:

{:providers {clojure-community {:edn-file
                                {:path "~/.config/bink/provider/clojure.edn"}}
             stuff-from-work {:sci-fn
                              (fn []
                                (cheshire.core/parse-string
                                 (slurp "")
                                 keyword))}}}
I asked about the ability to shell interpret Clojure with sci from babashka scripts a while ago, borkdude, and I think your reply was along the lines of "this is not yet supported, but could be considered". What are your thoughts now? This is absolutely not urgent. Simply adding link providers for {:slurp-edn {:url ""}} and {:slurp-json {:url ""}} would solve all my immediate needs. Shelling out to babashka is another option. Then I could also use all of babashka's default provided namespaces (like json for cheshire).

πŸ‘€ 1
borkdude10:09:48

Why not just use load-string?

teodorlu10:09:36

That's a very good point. I need to trust the code in the file regardless, so I won't get any security advantages by using sci over load-string.

teodorlu10:09:26

Load-string does indeed work for this!

teodorlu16:09:30

I decided to follow up on this track. I've got something working, but I'm not sure it's good for anyone else yet. I can now use this config file:

;; now in ~/.config/dbx/dbx.edn
{:providers {iterbart {:fn (fn []
                             (:links (cheshire.core/parse-string
                                      (slurp "")
                                      keyword)))
                       :embark-fn (fn [url]
                                    (babashka.process/process ["firefox" "-new-window" url]))}}}
with this script: https://github.com/teodorlu/play.teod.eu/tree/8048c10f413c1200dfac566e81815fd3ddce8b03/dbx/dbxx.clj --- I'm going to try using it for a bit myself before moving any further. The CLI is simple:
dbx provider # list providers
dbx nav # pick provider, then target, then embark
dbx nav PROVIDER # pick target, then embark.
--- https://play.teod.eu/dbx/

rads16:09:33

[email protected] has been released, which means it's time for the first public announcement! πŸŽ‰ https://clojurians.slack.com/archives/C06MAR553/p1663260244298349

πŸŽ‰ 10
πŸ‘ 1
escherize18:09:47

This is great stuff! It’s not immediately clear, so what do I need to do to get my software onto bbin?

rads19:09:15

Good question β€’ If your project has a deps.edn file, you can install it using the --git/url, --mvn/version, or --local/root options, which should be familiar if you've used the Clojure CLI tools β—¦ If your project is on GitHub, you can omit --git/url using the io.github.proj/repo syntax β€’ If you have a standalone .clj script, you can push it to GitHub and install it from the raw HTTP URL β—¦ Installing .clj files from the local filesystem is not implemented yet, but will be supported in the future Edit: I created a FAQ page with a little more info: https://github.com/babashka/bbin/blob/main/docs/faq.md#how-do-i-get-my-software-onto-bbin

plins19:09:05

Im trying to setup a babashka task like

{:min-bb-version "0.4.0"
 :tasks {fmt (shell "lein zprint $(git ls-files)")}}
but its failing with
Processing file: `$(git
Unable to process file: `$(git because: java.io.FileNotFoundException: `$(git (No such file or directory) Leaving it unchanged!
Processing file: ls-files)`
Unable to process file: ls-files)` because: java.io.FileNotFoundException: ls-files)` (No such file or directory) Leaving it unchanged!
is the shell fn able to do the expansion for me?

borkdude19:09:31

@plins No, it doesn't do bash expansion since bb is fully cross platform compatible and bash is not. You can do it like this:

(let [files (str/split-ilnes (:out (shell {:out :string} "git ls-files"))] ...)
or so

borkdude19:09:48

and then (apply shell "lein zprint" files)

borkdude19:09:14

(you might need to get rid of the last newline in the git output)

borkdude19:09:58

An antq script you can install with bbin:

bbin install 
Then run antq --help or just antq to see upgradable deps

πŸ†’ 2
rads21:09:51

This issue for installing multiple scripts from a single repo may be relevant for the borkdude/tools repo: https://github.com/babashka/bbin/issues/18