zed icon indicating copy to clipboard operation
zed copied to clipboard

Direnv environments are not picked up with either fish or nushell used

Open WeetHet opened this issue 1 year ago • 8 comments

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

Screenshot 2024-02-29 at 22 00 12

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

WeetHet avatar Feb 29 '24 20:02 WeetHet

@mrnugget, this seems like your stuff

WeetHet avatar Feb 29 '24 20:02 WeetHet

@mrnugget I have discovered a horrible hack for fish: add emit fish_prompt after cd, which triggers direnv Screenshot 2024-03-01 at 10 16 57

WeetHet avatar Mar 01 '24 08:03 WeetHet

Or do set -x __direnv_export_again; emit fish_preexec; Screenshot 2024-03-01 at 10 15 35

WeetHet avatar Mar 01 '24 08:03 WeetHet

Just to confirm this: you're running into this when trying to use gopls, right? Because no other place uses this method yet.

mrnugget avatar Mar 01 '24 08:03 mrnugget

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

WeetHet avatar Mar 01 '24 08:03 WeetHet

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?

mrnugget avatar Mar 01 '24 08:03 mrnugget

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?

We need to do that for every shell, I still don't know what should be done for nushell

WeetHet avatar Mar 01 '24 09:03 WeetHet

We can do fish for now and leave this open for suggestions on nushell

WeetHet avatar Mar 01 '24 09:03 WeetHet

This is available in Zed v0.126.0-pre.

JosephTLyons avatar Mar 06 '24 22:03 JosephTLyons

@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

WeetHet avatar Mar 06 '24 23:03 WeetHet