Direnv environments are not picked up with either fish or nushell used
Check for existing issues
- [X] Completed
Describe the bug / provide steps to reproduce it
The current way to pick up the environment as used in https://github.com/zed-industries/zed/blob/dab886f4794e8d14cc82dc8e4906e93b78aa8fe8/crates/project/src/project.rs#L9366-L9385
does not work with neither fish nor nu shells. This is because direnv has some weird behaviour preventing it from evaluating. The dirty fix would be to force evaluation:
let additional_command = match PathBuf::from_str(shell.as_str()) {
Ok(shell_path) if shell_path.file_name() == Some(OsStr::new("fish")) => {
Some("eval (direnv export fish)")
}
Ok(shell_path) if shell_path.file_name() == Some(OsStr::new("nu")) => {
Some("direnv export json | from json | default {} | load-env")
}
_ => None,
};
let command = match additional_command {
Some(additional_command) => format!(
"cd {dir:?}; {}; echo {marker}; /usr/bin/env -0; exit 0;",
additional_command
),
None => format!("cd {dir:?}; echo {marker}; /usr/bin/env -0; exit 0;"),
};
or something like that.
Environment
Zed: v0.125.1 (Zed Preview) OS: macOS 14.3.1 Memory: 8 GiB Architecture: aarch64
If applicable, add mockups / screenshots to help explain present your vision of the feature
If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.
If you only need the most recent lines, you can run the zed: open log command palette action to see the last 1000.
No response
@mrnugget, this seems like your stuff
@mrnugget I have discovered a horrible hack for fish: add emit fish_prompt after cd, which triggers direnv
Or do set -x __direnv_export_again; emit fish_preexec;
Just to confirm this: you're running into this when trying to use gopls, right? Because no other place uses this method yet.
Just to confirm this: you're running into this when trying to use
gopls, right? Because no other place uses this method yet.
Yeah, but its a more general problem with some tools (like direnv) requiring fish_prompt event to activate
Got it. I think special-casing fish and using emit fish_prompt after cd isn't that hacky. Why do you think it's hacky? What am I missing?
Got it. I think special-casing
fishand usingemit fish_promptaftercdisn't that hacky. Why do you think it's hacky? What am I missing?
We need to do that for every shell, I still don't know what should be done for nushell
We can do fish for now and leave this open for suggestions on nushell
This is available in Zed v0.126.0-pre.
@JosephTLyons please reopen as this is still not implemented for nushell. Also labeling this as help needed would be great as I have no idea how to fix nushell