So the invocation to serve a clojure.main REPL over a network socket is a bit of a mouthful (`clj -J-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"`).
I’m wondering whether it would make sense to add a built-in alias (like -X:deps) for launching a socket-based clojure.main REPL. Ideally, you’d be able to do something like clj -X:repl, which would launch a socket server serving a clojure.main REPL with :port 0. It’d then write the port number into a file (like Lein does with .nrepl-port). I believe Cursive can read a socket REPL port number from a file now, too, for example. Any trailing args would get passed to clojure.core.server/start-server.
I know I’m probably the only person in the world who wants this, but still, figured I’d ask. 🙂
the jvm has built in support for unix domain sockets now, seems a shame for new stuff for local tooling to continue to use network sockets
Bear in mind that -J... combines with any options -- as soon as you tie it to -X:deps, you've excluded a whole bunch of invocations (including -M based stuff).
from my .zshrc:
# sample usage: clj -J"$(socket-repl 6000)" ... or java "$(socket-repl 6000) -jar ...
socket-repl()
{
echo -n "-Dclojure.server.repl={:port $1 :accept clojure.core.server/repl}"
}You can always put an alias in your user deps.edn: https://github.com/seancorfield/dot-clojure/blob/develop/deps.edn#L55
you can vote for adding something to the cli for this here: https://ask.clojure.org/index.php/7830/first-class-options-for-socket-repl?show=7830#q7830
Then you can use that with -A or -M or -X 🙂
Yeah, I’m aware of those approaches (although neither automatically assigns an available port), but it’s an extra hurdle for brand new users, I think.
i use my socket-repl shell function all the time
Thanks, Alex! I’ll do that.
I do something like this:
(defn start-server
[_]
(let [server (server/start-server {:name "server" :port 0 :accept `server/repl :server-daemon false})
port (.getLocalPort server)
host (-> server .getInetAddress .getCanonicalHostName)
port-file (io/file ".repl-port")]
(.deleteOnExit port-file)
(spit port-file port)
(printf "Socket server listening on %s:%s\n" host port)))anyone who wants to suggest things for this could also add those to that question if we wanted to collect ideas there
I juggle so many projects that I don’t want to think about whether a port number’s free.
I also considered going with Unix domain sockets earlier, but I didn’t want to require Java 16. Also, it’s handy to be able to connect to a remote socket, too. I’m also not sure whether there’s any benefit to using Unix domain sockets over a network socket (other than avoiding the port number file hassle).