Fork me on GitHub
#tools-deps
<
2018-04-20
>
mfikes03:04:10

Try as I might, I can't find another way to embed deps EDN in a shebang without the Corfield Comma

8
seancorfield04:04:08

I'm honored -- I have punctuation named after me :rolling_on_the_floor_laughing:

☄️ 4
john14:04:06

Corfield comma 😂

john14:04:30

@mfikes this is exactly the simple static site generator I was looking for! thanks

john14:04:53

that's really simple

dominicm14:04:03

@mfikes just a caution, using the shebang that way won't work on Linux

mfikes14:04:35

@dominicm Yep. I know. I know.

mfikes14:04:29

It is a nice pattern for when you want a script to specify its own deps, but alas.

dominicm14:04:18

I came up with something that works

dominicm14:04:53

#!/bin/sh

"exec" "clj" "-Sdeps" "{:deps,{markdown-clj,{:mvn/version,\"0.9.85\"}}}" "$0" "$@"

(require '[markdown.core :refer [md-to-html-string]])
(println (md-to-html-string (first *command-line-args*)))
Run as ❯ ./foo.clj '# Hello, world' I don't know whether to share this or burn it

😱 16
😍 12
😆 4
dominicm14:04:16

You can kill the commas too, just tested

mfikes14:04:24

Nice, so the extra stuff there is just interpreted as strings by the compiler that otherwise do no harm 🙂

dominicm14:04:18

I had issues with your md->html, the docs said it was md-to-html? Dunno if in cljs it's different, but thought I would warn you

timgilbert15:04:13

That is a cool hack (also slightly horrifying)

timgilbert15:04:48

I'm wondering if various bits of clojure syntax farther down in the file would break bash, but I guess it really does just read line-by-line?

mfikes15:04:59

My guess is that exec seals the deal, replacing the script with the clj process, thus making it so no further bash interpreting is required

👍 4
Alex Miller (Clojure team)16:04:59

this still pales in comparison to boot’s hack I think - it embeds a jar file in the bash

mfikes16:04:15

😱

😱 4
mfikes16:04:57

Like, the binary image?

Alex Miller (Clojure team)16:04:16

just go edit your boot script :)

mfikes16:04:25

Hackers gonna hack

dominicm16:04:33

fun fact, zip readers scan the file until they find the header.

dominicm16:04:38

Capsule also has "really executable jars"

mfikes16:04:01

I like your solution @dominicm; it works on macOS as well. I’m thinking of putting it in the Planck online docs given it is so useful. https://github.com/planck-repl/planck/issues/720#issuecomment-383147716

dominicm16:04:50

@mfikes Go ahead! I'm also honoured you took the time to figure out my gh username 🙂

dominicm16:04:47

I tested it with a posix-only (ish) shell, so it should work everywhere

mfikes16:04:31

I forgot about the fact that it needs to be well-formed Clojure code and used single quotes above. Hrm. It still worked.

dominicm16:04:58

I guess that is well-formed clojure code, you are doing (quote "{:deps …") (quote "$0") 😂

dominicm16:04:10

you're not doing what it looks like you're doing, but it works

mfikes16:04:47

I think I’ll use \" as it is a little less mystifying

dominicm16:04:21

It's also way more annoying 😉

pesterhazy16:04:22

So much progress in one day! Corfield Comma... Monroe's Shebang

😂 12
pesterhazy16:04:50

I think I'd use clojure instead of clj. The latter is wrapped in rlwrap, which seems unnecessary for scripts

👍 8
pesterhazy16:04:31

Trying to code-golf:

#!/usr/bin/env bash
{ "exec" "clojure" "-Sdeps" "{:deps {markdown-clj {:mvn/version \"0.9.85\"}}}" "$0" "$@"
}

(require '[markdown.core :refer [md-to-html-string]])
(println (md-to-html-string (first *command-line-args*)))

pesterhazy16:04:43

not sure that's any better though

dominicm16:04:04

Isn't it exactly the same? 😂 Although I like the hack

pesterhazy17:04:08

Yeah, the real insight is in the different interpretation of strings by sh and clojure

mfikes17:04:17

Oddly, it works with ClojureScript, which I would have expected to take issue with some strings appearing before an ns form

#!/usr/bin/env bash
"exec" "clojure" "-Sdeps" "{:deps {org.clojure/clojurescript {:mvn/version \"1.10.238\"} funcool/tubax {:mvn/version \"0.2.0\"}}}" "-m" "cljs.main" "-re" "node" "$0" "$@"
(ns foo.core
  (:require [tubax.core :as tubax]))
(prn (tubax.core/xml->clj "<h1>foo</h1>"))
(prn *command-line-args*)

ghadi18:04:09

upgraded clj today, from 359 to 375, and I ran into the error Error building classpath. Destination path "my-private-lib" already exists and is not an empty directory Seems like this popped up recently.

Alex Miller (Clojure team)18:04:44

can you explain more about the context?

Alex Miller (Clojure team)18:04:24

was this on a linux install or using clj?

ghadi21:04:04

linux install, using clj