Fork me on GitHub
#babashka
<
2020-06-22
>
borkdude15:06:07

Variable expansion macro:

$ export BABASHKA_PRELOADS="(defmacro $ [x] `(System/getenv ~(str x)))"

$ bb '(-> ($ PWD) (str/split #"/") last)'
"clj-kondo" 

👍 12
nate18:06:06

oh cool, thanks for the reminder

borkdude18:06:21

thanks 🙂

nate18:06:52

thank you

lread20:06:05

Would it be of general interest to add https://clojure.github.io/clojure/clojure.java.browse-api.html to babashka? I ask because I’m writing a script that optionally launches a web browser. Not terrible for me if it does not make sense to add, just thought I’d ask.

borkdude20:06:19

It's not terribly important to me. The namespace has a weird dependency on java.awt.Desktop. This code could be problematic with GraalVM as well: https://github.com/clojure/clojure/blob/ef00c7cffad10e6104d333f7f71a29163b06cd0a/src/clj/clojure/java/browse.clj#L57-L64

lread20:06:10

ah ok, not worth the bother!

borkdude20:06:42

My guess would be that if Clojure was written from scratch again, this might not get into the core

lread20:06:20

It is a bit odd.

lread20:06:46

I guess cljs uses it to bring up the browser…. wonder if it was added for that…

borkdude20:06:44

Could be wrong though. And I have used it in the past a couple of times. For bb it's probably not so hard to write a cross platform browser opening script, that calls open on macOS, xdg-open on linux, and start on Windows

borkdude20:06:16

which is also more general than just browsers

lread20:06:04

hmmm… looks like it more than just browsers in clojure too. It acts like open on the mac. For example (browse/browse-url ".") opens finder in the current directory.

borkdude20:06:25

@lee I would be open to a PR that adds clojure.java.browse/browse-url, but only shells out and doesn't use the reflection or swing stuff.

borkdude20:06:39

so our own implementation of it

lread20:06:34

Ok, I’ll jot a note… and maybe get to it someday (but also maybe not simple_smile).

lread21:06:11

ok… thanks!

lukasz21:06:53

@lee FWIW - open and xdg-open do all of this for you in OSX and Linux respectively, so could be just a one-liner. No idea about Windows

borkdude09:06:07

@lukaszkorecki @lee I've included clojure.java.browse/browse-url here now: https://clojurians.slack.com/archives/CSDUA8S6B/p1592905277013100 Feel free to give it a test run

borkdude10:06:21

Hmm:

C:\Users\borkdude\Downloads>bb -e "(require '[clojure.java.browse :refer [browse-url]]) (browse-url \"\")"
java.io.IOException: Cannot run program "start": CreateProcess error=2, The system cannot find the file specified [at line 1, column 54]

lread12:06:54

@U04V15CAJ, you are a dynamo! maybe start is part of the shell and needs something like cmd /c start

lread12:06:22

also saw this nuance which might be relevant? https://superuser.com/a/1335757

borkdude12:06:06

Yeah, tried cmd /c, see the issue

lread12:06:05

oh... sorry have not had coffee yet!

lread21:06:50

thanks @lukaszkorecki, I’ve added your note to the issue.

borkdude21:06:52

yep, I also said that here: > that calls open on macOS, xdg-open on linux, and start on Windows https://clojurians.slack.com/archives/CLX41ASCS/p1592859104311400 🙂

borkdude21:06:24

I had to google this, so thanks for confirming I googled it right 🙂

lukasz21:06:32

ha, missed it - also TIL about start

borkdude21:06:06

there is some code around cygwin in the original namespace - I wonder if that's still relevant in 2020

borkdude21:06:35

I'll run some tests in Windows to confirm if start also works in Cygwin, later