diff options
| author | Grégoire Duchêne <gduchene@awhk.org> | 2022-02-12 13:46:20 +0000 |
|---|---|---|
| committer | Grégoire Duchêne <gduchene@awhk.org> | 2022-02-12 13:46:20 +0000 |
| commit | b3162b3adb75dd7856329d7bebf8b91bcbbf47ed (patch) | |
| tree | 4dfb7c9a26165961e04f03222324b17780b91644 /dotfiles-darwin/bin | |
| parent | 127705b957339b1d4b70ff33488d5b9b53872316 (diff) | |
darwin/env.sh: Set SSH_AUTH_SOCK in Emacs.app
Diffstat (limited to 'dotfiles-darwin/bin')
| -rwxr-xr-x | dotfiles-darwin/bin/env.sh | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/dotfiles-darwin/bin/env.sh b/dotfiles-darwin/bin/env.sh index 518962d..5dd76b0 100755 --- a/dotfiles-darwin/bin/env.sh +++ b/dotfiles-darwin/bin/env.sh @@ -3,18 +3,24 @@ zmodload zsh/datetime echo_log() { echo $(strftime %+) - $@ } -for env (DOMAIN HOST SSH_AUTH_SOCK UNAME - XDG_{{CACHE,CONFIG,DATA}_HOME,RUNTIME_DIR}); do +for env in DOMAIN HOST UNAME XDG_{{CACHE,CONFIG,DATA}_HOME,RUNTIME_DIR}; do echo_log Setting ${env} to “${(P)env}”. launchctl setenv ${env} ${(P)env} done -# PATH is magic on macOS, and since it only matters for Emacs, let’s -# make it work in Emacs only. Yep, it’s pretty bad. +# Some environment variables are magic: setting them with launchctl does +# not seem to work with Emacs. I’m not sure why, but adding those to +# Info.plist does work. local plist=~/Applications/Emacs.app/Contents/Info.plist -if [[ -f ${plist} ]]; then - local json_path='{"PATH": "'${PATH}'"}' - echo_log Setting PATH in Emacs.app to “${json_path}”. - plutil -replace LSEnvironment -json ${json_path} ${plist} - /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f ${plist:h:h} + +if [[ ! -f ${plist} ]]; then + echo_log No Info.plist file found at “${plist}”. + return fi + +plutil -insert LSEnvironment ${plist} 2>/dev/null >&2 || true +for env in PATH SSH_AUTH_SOCK; do + echo_log Setting LSEnvironment.${env} in Emacs.app to “${(P)env}”. + plutil -replace LSEnvironment.${env} -string ${(P)env} ${plist} +done +/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f ${plist:h:h} |
