# Properly load environment variables from the login shell \(\#31799\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/55120c42310f0abc889f597e6043be99928baf92)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 55120c42310f0abc889f597e6043be99928baf92

Requested commit: 55120c42310f0abc889f597e6043be99928baf92

Commit: 55120c42310f0abc889f597e6043be99928baf92

Tree: f2d7c6afcdf0e710d44b895282b11590c0f447c1

Author: Haru Kim

Committer: GitHub

## Message

```
Properly load environment variables from the login shell (#31799)

Fixes #11647
Fixes #13888
Fixes #18771
Fixes #19779
Fixes #22437
Fixes #23649
Fixes #24200
Fixes #27601

Zed’s current method of loading environment variables from the login
shell has two issues:
1. Some shells—​fish in particular—​​write specific escape characters to
`stdout` right before they exit. When this happens, the tail end of the
last environment variable printed by `/usr/bin/env` becomes corrupted.
2. If a multi-line value contains an equals sign, that line is
mis-parsed as a separate name-value pair.

This PR addresses those problems by:
1. Redirecting the shell command's `stdout` directly to a temporary
file, eliminating any side effects caused by the shell itself.
2. Replacing `/usr/bin/env` with `sh -c 'export -p'`, which removes
ambiguity when handling multi-line values.

Additional changes:
- Correctly set the arguments used to launch a login shell under `csh`
or `tcsh`.
- Deduplicate code by sharing the implementation that loads environment
variables on first run with the logic that reloads them for a project.



Release Notes:

- N/A
```

## Parents

- [8227c45a11e2af162e02911706228f3079461ad2](https://git.cafe/gitcafe/zed/commit/8227c45a11e2af162e02911706228f3079461ad2?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/55120c42310f0abc889f597e6043be99928baf92?format=markdown)
