aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2023-01-31 09:18:47 -0500
committerMitchell Riedstra <mitch@riedstra.dev>2023-01-31 09:18:47 -0500
commit3ec03e61f49231502ca7e5e87d7895bea90f11bc (patch)
tree32c886529b442bcfce66e626f2fe1b2e33371eb1
parent8d1417b53842b9667f2a6b049cf33dabb47c3f4e (diff)
downloaddwm-3ec03e61f49231502ca7e5e87d7895bea90f11bc.tar.gz
dwm-3ec03e61f49231502ca7e5e87d7895bea90f11bc.tar.xz
Allow for loading of environment variables on start
-rw-r--r--dwm.c3
-rw-r--r--util.c19
-rw-r--r--util.h1
3 files changed, 23 insertions, 0 deletions
diff --git a/dwm.c b/dwm.c
index f18658b..d9ea0d7 100644
--- a/dwm.c
+++ b/dwm.c
@@ -2455,6 +2455,9 @@ main(int argc, char *argv[])
if (!(dpy = XOpenDisplay(NULL)))
die("dwm: cannot open display");
checkotherwm();
+ FILE *fh;
+ if ((fh = fopen(".env", "r")))
+ readEnv(fh);
setDmenuFlags();
setup();
#ifdef __OpenBSD__
diff --git a/util.c b/util.c
index 06685ad..7ec62ba 100644
--- a/util.c
+++ b/util.c
@@ -64,3 +64,22 @@ reMatch(const char *regex, const char *str) {
return rc;
}
+
+int
+readEnv(FILE *fh)
+{
+ int ret;
+ char *name = alloca(1024*sizeof(char)), *value = alloca(8192*sizeof(char));
+
+ while (1) {
+ if ((ret = fscanf(fh, "%1023[^=]=%8191[^\n]\n", name, value)) == EOF)
+ break;
+ else if (ret == 0)
+ break;
+
+ fprintf(stderr, "Setting: '%s' = '%s'\n", name, value);
+ setenv(name, value, 1);
+ }
+
+ return 0;
+}
diff --git a/util.h b/util.h
index cd7c08d..547d976 100644
--- a/util.h
+++ b/util.h
@@ -7,3 +7,4 @@
void die(const char *fmt, ...);
void *ecalloc(size_t nmemb, size_t size);
int reMatch(const char *regex, const char *str);
+int readEnv(FILE *fh);