summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrégoire Duchêne <gduchene@awhk.org>2020-07-05 01:43:34 +0100
committerGrégoire Duchêne <gduchene@awhk.org>2020-07-05 01:43:34 +0100
commit4435c0efc83b8fd0c2cae0a5fe0ce886b794552b (patch)
treeb8374325bbdf607499009e47953890e833da8b71
parent37a5938a0fb4d04ce9684ba2cfc517cb8e947926 (diff)
darwin/bin: Add env.sh
This short script defines a few environment variables with launchctl so macOS apps can access them.
-rwxr-xr-xdotfiles-darwin/bin/env.sh5
-rw-r--r--dotfiles-darwin/launchd/Makefile8
-rw-r--r--dotfiles-darwin/launchd/org.awhk.env.plist14
3 files changed, 27 insertions, 0 deletions
diff --git a/dotfiles-darwin/bin/env.sh b/dotfiles-darwin/bin/env.sh
new file mode 100755
index 0000000..00c1bfa
--- /dev/null
+++ b/dotfiles-darwin/bin/env.sh
@@ -0,0 +1,5 @@
+#!/usr/bin/env zsh
+
+for env in PATH UNAME XDG_{{CACHE,CONFIG,DATA}_HOME,RUNTIME_DIR}; do
+ launchctl setenv ${env} ${(P)env}
+done
diff --git a/dotfiles-darwin/launchd/Makefile b/dotfiles-darwin/launchd/Makefile
new file mode 100644
index 0000000..54d7b2a
--- /dev/null
+++ b/dotfiles-darwin/launchd/Makefile
@@ -0,0 +1,8 @@
+export ENV_SH := $(realpath ../bin/env.sh)
+
+all: $(foreach plist, $(wildcard *.plist), ~/Library/LaunchAgents/${plist})
+
+~/Library/LaunchAgents/%.plist: %.plist
+ envsubst < $< >$@
+ -launchctl unload $@ 2>/dev/null
+ launchctl load $@
diff --git a/dotfiles-darwin/launchd/org.awhk.env.plist b/dotfiles-darwin/launchd/org.awhk.env.plist
new file mode 100644
index 0000000..f2da1d5
--- /dev/null
+++ b/dotfiles-darwin/launchd/org.awhk.env.plist
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+ <dict>
+ <key>Label</key>
+ <string>org.awhk.env</string>
+
+ <key>Program</key>
+ <string>${ENV_SH}</string>
+
+ <key>RunAtLoad</key>
+ <true/>
+ </dict>
+</plist>