This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-03
Channels
- # aleph (1)
- # announcements (9)
- # babashka (3)
- # beginners (200)
- # calva (22)
- # cider (74)
- # clojure (97)
- # clojure-dev (43)
- # clojure-europe (15)
- # clojure-italy (4)
- # clojure-nl (4)
- # clojure-sanfrancisco (2)
- # clojure-uk (103)
- # clojuredesign-podcast (2)
- # clojurescript (45)
- # core-async (5)
- # cursive (13)
- # datomic (42)
- # emacs (20)
- # fulcro (6)
- # graalvm (37)
- # jackdaw (10)
- # leiningen (7)
- # mid-cities-meetup (3)
- # off-topic (2)
- # pathom (1)
- # pedestal (3)
- # re-frame (6)
- # reagent (38)
- # reitit (5)
- # shadow-cljs (117)
- # spacemacs (1)
- # sql (1)
- # tools-deps (17)
- # vim (14)
- # xtdb (18)
how we can programatically get the list of loaded aliases ?
This would be the public API for that I think (I know, this isn't about tools.deps):
user=> (require '[clojure.string :as str])
nil
user=> (ns-aliases *ns*)
{str #object[clojure.lang.Namespace 0x301d8120 "clojure.string"]}
back to original question @U0516053R :
prova@99-65642 ~/Downloads> clj -A:prof
Clojure 1.10.1
user=> (require '[clojure.java.shell :refer (sh)])
user=> (sh "ps" "-p" (-> (java.lang.ProcessHandle/current) .parent .get .pid str))
{:exit 0, :out " PID TTY TIME CMD\n70965 ttys003 0:00.01 rlwrap -r -q \\\" -b (){}[],^%#@\";:' clojure -A:prof\n", :err ""}
I don’t think there is a good and reliable way to figure it out, because clj launches a new process with classpath, so no alias information is really available to the jvm
with that said, you can lookup your PID, lookup parent PID, run ps
(linux and mac only) to find information about parent PID and extract some info from that: as you see, :out
contains invocation string
note: ProcessHandle is available since JDK 9, previous JDKs will require some reflection and googling to get pids..
@U47G49KHQ thank you
Can you back up to what you are trying to do?
I'd like to take code action based on the existence of dev alias when connecting to database.
yeah, I would add something extra that is explicit for that case, don't rely on all that process stuff above
system property, include dev resources in classpath, etc
Thank you @alexmiller and @borkdude.