-
Notifications
You must be signed in to change notification settings - Fork 49
Description
A more elegant way of calling env variables could be interesting. Currently we can do: ,(string ($<_ echo $HOME) "/folder") or ,(string (os/getenv "HOME") "/folder") but maybe e.g. (env $HOME) or even (env :home) could be nice, transparently implemented as the above. (I have no idea how to safely implement just using $HOME directly.) Unfortunately ~ can't be a binding. 💃
(get-env :home) might be more Janety, but I'm not sure if redoing the whole API makes sense that way. More direct, implementing something like:
(defn- fetch-env []
(def e @{})
(each line (string/split "\n" (string/trim ($< env)))
(def [k v] (string/split "=" line 0 2))
(put e k v))
e)Could let you do: (defn env [s] ((fetch-env) s)) allowing (env "PWD") but exposing the map directly could be optimal e.g. an API like ((fetch-env) "PWD"). Naming is of course an issue, we do have the model of curenv though.
LispE has some inspiring features: https://www.youtube.com/watch?v=aeUt0x7EqPY
Racket's Rash https://www.youtube.com/watch?v=Acjqx1MPkw4 h/t sogaiu
What do others thing of such things? Does anything else seem useful? N.b. much of my use case is jumping immediately into a Janet repl instead of bash, so short things feel extra convenient. If others don't find such use cases relevant, it'd make more sense to add them to a personal utility lib (and name it "s" for a short (use s)!)