direnv: Allow disabling env integration entirely (#43764)

Relates to #35759, but maybe doesn't entirely fix it? I think it will
improve the situation, at least.
Also provides a workaround for the issue described in
https://github.com/zed-industries/zed/issues/40094#issuecomment-3559808526
for users of WSL + `nix-direnv`.

Rationale: there are cases where automatic direnv integration is not
always desirable, but Zed currently has no way of opting out of this
integration besides `direnv revoke` (which is often not desirable).

This PR provides such an opt-out for users who run into problems with
the existing direnv integration methods. Some reasons why disabling
might be useful:
- Security concerns about auto-loading `.envrc` (arguably, `direnv
revoke` should cover this most of the time)
- As in #35759, for users who use different shells/envs for
interactive/non-interactive cases and want to manually control the
environment Zed uses
- As in #40094, to workaround OS limits on environment variable /
command-line parameter size


Release Notes:

- Added the ability to disable direnv integration entirely
This commit is contained in:
Ian Chamberlain
2025-12-01 08:58:30 +01:00
committed by GitHub
parent d1d419b209
commit db86febc0c
4 changed files with 11 additions and 1 deletions
+5
View File
@@ -314,6 +314,10 @@ async fn load_directory_shell_environment(
load_direnv: DirenvSettings,
tx: mpsc::UnboundedSender<String>,
) -> anyhow::Result<HashMap<String, String>> {
if let DirenvSettings::Disabled = load_direnv {
return Ok(HashMap::default());
}
let meta = smol::fs::metadata(&abs_path).await.with_context(|| {
tx.unbounded_send(format!("Failed to open {}", abs_path.display()))
.ok();
@@ -355,6 +359,7 @@ async fn load_directory_shell_environment(
// even if direnv direct mode is enabled.
let direnv_environment = match load_direnv {
DirenvSettings::ShellHook => None,
DirenvSettings::Disabled => bail!("direnv integration is disabled"),
// Note: direnv is not available on Windows, so we skip direnv processing
// and just return the shell environment
DirenvSettings::Direct if cfg!(target_os = "windows") => None,