Hasty Briefsbeta

Bilingual

Handling environment variables in Emacs on OS X and Linux

5 hours ago
  • The article addresses how to handle environment variables in Emacs on OSX and Linux, especially when Emacs is launched from Finder or Dock rather than a shell.
  • The author avoids the `exec-path-from-shell` package due to startup slowness and preference to avoid subprocess invocation, instead adopting a method similar to Doom Emacs.
  • Code is added to `early-init.el` to load environment variables from a generated file (`env`) located in the user Emacs directory, parsing each line to set environment variables.
  • A script called `emacs-refresh-env` is created to generate the `env` file by running `zsh -ic env`, filtering out unwanted variables (e.g., shell bookkeeping, Tmux/Alacritty noise) and sorting the output.
  • The trade-off is that the `env` file must be regenerated after any environment variable changes, so the script is integrated into an `update-all` script to run periodically.