nushell / nushell

A new type of shell
https://www.nushell.sh/
MIT License
31.65k stars 1.62k forks source link

`$nu.data-dir` on mac is pointing to wrong location #13704

Open maxim-uvarov opened 2 weeks ago

maxim-uvarov commented 2 weeks ago

Describe the bug

I have $env.XDG_CONFIG_HOME set and it is used for configs, yet nushell doesn't recognize it

How to reproduce

> $nu.config-path
/Users/user/.config/nushell/config.nu

> $nu.data-dir
/Users/user/Library/Application Support/nushell

Expected behavior

I expect this variable to point to the right dir

Screenshots

No response

Configuration

key value
version 0.97.1
major 0
minor 97
patch 1
branch
commit_hash
build_os macos-aarch64
build_target aarch64-apple-darwin
rust_version rustc 1.78.0 (9b00956e5 2024-04-29)
rust_channel stable-aarch64-apple-darwin
cargo_version cargo 1.78.0 (54d8815d0 2024-03-26)
build_time 2024-08-21 09:24:44 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, system-clipboard, trash
installed_plugins polars 0.97.1, regex

Additional context

No response

fdncred commented 2 weeks ago

This is the code. So, it looks like it's failing to find the env var and falling back to the default. I'm guessing that this means you don't have XDG_CONFIG_HOME set before launching nushell? https://github.com/nushell/nushell/blob/da98c23ab3639ab78cadf2fe71ffbca42048b168/crates/nu-path/src/helpers.rs#L8-L14

maxim-uvarov commented 2 weeks ago

@fdncred Nope, I have the $XDG_CONFIG_HOME set before the launch. I checked the situation on two machines.

On my main machine in wezterm.lua, I have this:

config.default_prog = { '/Users/user/.cargo/bin/nu', '-l'}

config.set_environment_variables = {
XDG_CONFIG_HOME = '/Users/user/.config'
}

For example, the history path works as expected:

> $nu.history-path
/Users/user/.config/nushell/history.sqlite3
maxim-uvarov commented 2 weeks ago

@fdncred I found it.

I also need to set $env.XDG_DATA_HOME, not just $env.XDG_CONFIG_HOME.

However, it's not documented or intuitive. Maybe nushell can check if $env.XDG_DATA_HOME is not set, then check the $env.XDG_CONFIG_HOME variable on Mac, and only then fall back to the default?

fdncred commented 2 weeks ago

oh ya, that's what the code says. LOL