1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-07 20:12:27 +00:00

Extend environment variable behavior to NO_COLOR and JANET_PROFILE

Env vars set to empty strings should behave the same as unset variables.
This commit is contained in:
Calvin Rose
2025-10-04 13:12:29 -05:00
parent c901edbfb9
commit db7f741dad

View File

@@ -4556,7 +4556,10 @@
###
# conditional compilation for reduced os
(def- getenv-alias (if-let [entry (in root-env 'os/getenv)] (entry :value) (fn [&])))
(def- getenv-raw (if-let [entry (in root-env 'os/getenv)] (entry :value) (fn [&])))
(defn- getenv-alias [env-var &opt dflt]
(def x (getenv-raw env-var dflt))
(if (= x "") nil x)) # empty string is coerced to nil
(defn- run-main
[env subargs arg]
@@ -4634,12 +4637,11 @@
(var expect-image false)
(when-let [jp (getenv-alias "JANET_PATH")]
(unless (empty? jp)
(def path-sep (if (index-of (os/which) [:windows :mingw]) ";" ":"))
(def paths (reverse! (string/split path-sep jp)))
(for i 1 (length paths)
(module/add-syspath (get paths i)))
(setdyn *syspath* (first paths))))
(def path-sep (if (index-of (os/which) [:windows :mingw]) ";" ":"))
(def paths (reverse! (string/split path-sep jp)))
(for i 1 (length paths)
(module/add-syspath (get paths i)))
(setdyn *syspath* (first paths)))
(if-let [jprofile (getenv-alias "JANET_PROFILE")] (setdyn *profilepath* jprofile))
(set colorize (and
(not (getenv-alias "NO_COLOR"))