This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-20
Channels
- # adventofcode (38)
- # announcements (8)
- # aws (4)
- # babashka (131)
- # beginners (263)
- # calva (2)
- # clj-kondo (12)
- # cljdoc (12)
- # cljsrn (3)
- # clojure (122)
- # clojure-europe (3)
- # clojure-finland (2)
- # clojure-nl (13)
- # clojure-uk (80)
- # clojured (1)
- # clojuredesign-podcast (3)
- # clojurescript (78)
- # core-async (19)
- # cursive (19)
- # datomic (7)
- # duct (10)
- # events (1)
- # fulcro (7)
- # graalvm (12)
- # graphql (3)
- # juxt (4)
- # malli (10)
- # music (3)
- # nrepl (4)
- # off-topic (25)
- # pathom (4)
- # pedestal (1)
- # re-frame (78)
- # reagent (8)
- # shadow-cljs (91)
- # sql (8)
- # vim (3)
- # xtdb (2)
Really enjoying babashka. Life's too short to remember how to write bash code. I feel liberated. Thanks a million @borkdude!
sure!
I added this now: https://github.com/borkdude/babashka/blob/master/README.md Can you check if you still agree?
@deleted-user borkdude may be around later to give you an answer
@deleted-user can you give an example of what exactly you need and why you need it in an issue?
Iām not aware that Clojure itself provides the name of the current file, but it does provide the name of the current namespace
Due to a typo re-quote-replacement
is not available... I'll fix the typo. Sorry about that š
Fixed on master:
$ lein bb '(clojure.string/re-quote-replacement "string \\ $")'
"string \\\\ \\$"
Ah, Clojure can do this:
(def x 1)
(println (:file (meta #'x)))
$ clj /tmp/foo.clj
/tmp/foo.clj
So that would be nice to add I guess.Here's a list of breaking changes so far: https://github.com/borkdude/babashka/blob/master/CHANGES.md
@plexus Is your blog open source? If you're open to it, I could do a PR to update *in*
to <input>
I added a list of currently known blog articles about babashka: https://github.com/borkdude/babashka#blogs
Considering clj-http-lite for bb:
$ bb "(require '[clj-http.lite.client :as client]) (:status (client/get \"\"))"
200
Rationale: idiomatic http client. clj-http has been around for a long time, "defacto" lib, but vanilla clj-http doesn't work with GraalVM. clj-http-lite is the GraalVM version that comes closest
Alternative: expose necessary Java classes to build your own requests (but contrary to java.time that seems tedious)
$ bb -e "(require '[clj-http.lite.client :as client]) (client/post \"\" {:body (json/generate-string {:a 1})})" | bb '(keys <input>)'
(:headers :status :body)
Binaries with clj-http-lite included:
Linux: https://2646-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.45-SNAPSHOT-linux-amd64.zip
Mac: https://2647-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.45-SNAPSHOT-macos-amd64.zip
Branch: clj-http
@deleted-user Again, could you give an example (or maybe an issue) with how that is supposed to work? I commented on it above
@deleted-user If you mean the joker.filepath
namespace: there is support for Java interop in babashka for
, java.nio.*
+ the
namespace. This should give you what you need while also maintaining compatibility with normal Clojure
it's nice to be able to make symlinks for sure -- unfortunately, recent experiments suggest this won't work on windows 10 until jdk 13 š
this was what i was trying: https://gist.github.com/sogaiu/cfa1484d9c3ca875b13f0c3ac75c6c73
wsl2 is not an option yet iiuc -- also i am using vms where it is questionable whether it will be practical to use.
i am skeptical of the wsl approach as being an interim bandaid solution -- wsl2 probably exists for a reason...one of thoese being that wsl was not good enough?
if possible, i'd like what i build to run with less requirements -- it's unclear to me whether using wsl2 is going to be a worthwhile trade-off
There's a bit about Windows Terminal here: https://conan.is/blogging/clojure-on-windows.html
> Follow the official instructions to install the clojure cli tools in bash in WSL. Cursive will use its own, built-in version for now (see below), although the Clojure CLI tools for Windows are coming.
it mentions the long classpath issue -- cursive apparently has its work-around. btw, i took timgilbert's pathing jar efforts (TDEPS-120) and made this: https://github.com/sogaiu/clj-pathing-jar
btw, i mention this pathing jar thing, because i have succeeded in using it (with some modifications) to build a native-image executable directly with native-image on windows. so it's not necessary to build an uberjar first.
on a related note, i've been talking to taylorwood about some related issues in clj.native-image -- may be eventually that will be usable for windows use.
i like the idea of being able to determine the current file location. (as a side note, unless it's going to be a dynamic var, i'm not a fan of using the earmuffs.)
is it a dynamic var in joker? I think it could be <file>
, since we already have <input>
although clojure has *command-line-args*
which is a bit inconsistent I guess, but maybe that was introduced before the earmuffs convention
@deleted-user What is the value of file in a script that you use with require
in joker
Oh btw, it seems like *command-line-args*
is a dynamic var:
(binding [*command-line-args* 2])
Darn. Maybe it makes sense to introduce *input*
instead of <input>
then, because it will be bound by babashka itself to some value
Welcome to joker v0.14.0. Use EOF (Ctrl-D) or SIGINT (Ctrl-C) to exit.
user=> (binding [*file* 2])
nil
as long as the thing is going to be a dynamic var and not change its name, i think it makes sense to use the earmuffs
i haven't played enough with *in*
/ *input*
/ <input>
to have an opinion about whether it should be a dynamic var -- may be other people are in a better position to have an informed opinion š
well, <input>
is really a delay which will be realized the first time it's evaluated
@deleted-user It reads EDN by default
I think keeping the notation for <input>
might make sense, since it is a bit magic in this respect
This is more for one-liners, not really for scripting, where you can just use read-line
et al
babashka started out as a tool to do just little sprinkles of clojure in between bash expressions, but now it's growing more towards a full scripting solution
i have a similar interest -- am hoping eventually for a crossplatform solution. don't want to maintain (or write) both bash and powershell.
Thank you. Yes, it's not perfect yet, and the more exposure it gets, the better it gets hopefully
@deleted-user Right, we could use the --classpath
option you mean?
@deleted-user No, a classpath is just a collection of directories and jar files that will be searched for a matching file
@deleted-user There's a workaround for that:
$ cat script.clj
#!/bin/sh
#_(
"exec" "bb" "$0" hello "$@"
)
(prn *command-line-args*)
./script.clj 1 2 3
("hello" "1" "2" "3")
Right now you can also use: /tmp/foo.clj (chmod +x)
#!/bin/sh
#_(
"exec" "bb" "$0" "$0" "hello" "$@"
)
(prn *command-line-args*)
In some other dir:
$ /tmp/foo.clj
Prints:
("/tmp/foo.clj" "hello")
In normal Clojure, you could probably read the metadata from a var and inspect the :file
property. Have you tried if this works? If it does, we can just do that.
clj-http-lite is going to obsolete my awesome curl wrapper! oh well š
@deleted-user Where do you read this? Vars were recently introduced
It would be good to see what clojure
makes of it, when you execute clojure script.cljc
like others, I find myself writing slightly larger scripts than the few-liners that glue together chunks of bash.
@deleted-user This seems to work for getting the scripting directory using clojure
:
(def x)
(require '[ :as io])
(def script-dir (.getParentFile (io/file (:file (meta #'x)))))
Someone also mentioned https://github.com/schmee/java-http-clj which relies on JDK 11
You could give it a try, but it requires some understanding of how files are processed either with passing a file argument, load-file
and require
. The way we handle classpath loading with a callback fn needs to change as well. I think it would be best if I gave it some more hammock time first
here's where I am on this script. ~/Sync/dotfiles is where the script sits and subdirectories have the dotfiles:
@sogaiu I added a table to illustrate the combinations of input and output flags: https://github.com/borkdude/babashka/#input-and-output-flags
Small follow up to this morning's breaking change: https://github.com/borkdude/babashka/releases/tag/v0.0.45


