-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config: history files should be stored in $XDG_STATE_HOME #10100
Comments
Nushell isn't XDG compliant, as you've noticed. There is a PR to fake it for the config file but not for the history. We talked about that PR recently and it may not ever land. The real crux of the issue is that nushell is cross platform and not just a Linux shell. So, nushell can't rely on Linux things like this. The second issue is that in order to read the XDG env vars at startup or login, you'd have to know where the config is before trying to read it, cross platform. So, you can't read a config file to know where the config file is and then read where the config file is that you found. |
Hmm, I see the problem. In that case, would it be acceptable for the developers of nushell and the users to simply treat the XDG env vars as undefined at nushell startup because of the problem you mentioned? The spec mentions that if the env vars are empty, the default values must be assumed by the app, not the OS. It would be a compromise and not fully compliant, because the XDG env vars are not read by nushell. So this is what I was thinking of (in pseudo-code):
This skips reading the env vars at startup because of the problem you mentioned. |
This is essentially hard coding the paths, which is what we do now, but the paths are set by the nushell/crates/nu-path/src/helpers.rs Lines 9 to 12 in d2abb86
|
I see, so the problem is that crate. It doesn't define the The ideal case would be for the crate to define something like At least the crate has It's a compromise, yes, because theoretically Some Linux/XDG elitists are definitely going to hate me for this comment, but I think For example, the Arch Wiki defines
I am pretty sure history counts as "user-specific data files". |
Isn't
|
Ideally this would be the case, but in practice I don't think many programs end up using The fish shell had a similar issue were it was discussed whether |
We used to use |
I'm not sure I understand this. Nushell just needs to check the relevant XDG environment variable, right? That doesn't involve reading a config file. |
Moreover, most modern terminals have the ability to setup the environment variables for you. Even the infamously feature-less Alacritty has this. So I don't understand why we're depriving those users the ability to choose where there files go. The argument that you can't provide a feature to anyone just because you can't provide the feature to everyone seems pretty bad to me. |
@rgwood Here's my reasoning. If nushell is your login shell, what environment is it reading from to get XDG info? If there is no environment, then you have to read an env.nu file from somewhere to get XDG info that tells you where to read the other config files from. The real crux here is being able to document how to set system level environment variables, for the operating systems we support, without regard to login shell. Otherwise, we'll get inundated with how to set these and how to support these features and in my view could cripple nushell. There is the terminal work-around that @utkarshgupta137 mentions, but for me, that seems like more of a hopeful-hack and difficult to support where we'd be reliant on upstream terminal to support this to use this nushell feature. So, we're back to being this, if we are reliant only on nushell, you have to load a env.nu file from somewhere that has the XDG env var set, and then go to that location and load those config files. My solution to all of this was how the closed PR was finally implemented, which was to always read from ~/.config, on every os and default to that, unless the os level directories already exist, then read from those. So, essentially there is no environment reading, it's just hard coded to one of two possible places.
@utkarshgupta137 This is called cross platform development. We try our very best to offer everything everywhere unless it is expressly prohibited by the environment. For instance, there is a |
I personally don't find this argument convincing. Should Nushell also stop supporting ANSI colors because some terminals might not support ANSI colors?
So isn't this an argument in favor of supporting features even if they're not available everywhere? Although, I disagree with the premise that XDG isn't supported on Windows, since quite a few CLI & terminals tools use it. |
Nushell's launched by the OS or your terminal, and they should be able to set environment variables for a login shell. On Linux you can edit I think we can assume that users who care about this feature will be able to figure out a way to launch Nushell with a specific environment variable set. |
I've tested this in the path and concluded that it didn't work. Maybe I did something wrong. This is the contents of my
I have nushell set to my login shell. I launch WSL and there is neither XVAR1 nor XDG_BLAH in my environment. |
@rgwood Correct me if I'm wrong, but the problem is that many For example, my system's login manager loads environment variables using sh and Quoting the fish shell issue I linked before:
Using a terminal emulator like @utkarshgupta137 mentioned, delegating it to the login manager, or running another shell beforehand are some ways around this. But the downside is that it will be on the user to ensure a consistent environment for nushell in every place that it can be run interactively. For example, the Then again, I agree that users should have to option to set Otherwise, another possible solution is to make an equivalent to $env.XDG_STATE_HOME = ($env.HOME | path join 'state_dir') This would enforce a similar |
^good points, thanks; you're right that system env vars may not be appropriate for something user-specific.
This seems correct to me. |
I think you can't have "immutable" and "user-specific" in the same sentence. By the very definition, if the contents of the data depend on the user, then the data is mutable. If you mean "not runtime mutable after written once", then why isn't that data in I don't believe
Can confirm. 36 entries in The folks over at Neovim were also surprised that Personally, I think that yet another directory is a little over-engineered. It's hard enough to just keep In the end, what matters most is that we have The separation itself, of config and history, is what's important. |
i think this is very sensible and i quite dislike myself having the history and |
The only thing you did wrong is assume that WSL would behave the same as a "normal" Linux system ;-). In most cases, you'd be correct, but this is one of those areas where WSL behaves differently. On a normal Linux system, However, WSL typically doesn't run the But that's why you didn't see any change here. You could manually "force" it by running If, for WSL, you wanted to set it for one environment, as mentioned, you could handle that through the parent process (e.g. Windows Terminal or VSCode), but as you mentioned, those wouldn't necessarily be in sync. However, a better solution with WSL would be to (untested, at least not recently):
And that will keep the environment the same for all WSL sessions regardless of where you launch it from. Other random thoughts on this issue. I don't think this adds anything new, but summarizes several viewpoints above:
|
I think most critically I would just like to be able to run I do still want to have history, as I very often just want to It would be more convenient to just be able to change the directories |
Any chance this could/should be coupled with the work in #12103 if/when that happens? It seems to be tightly related and probably needs the exact same skill-level to implement. |
@akyoto After considering this for a while, do you have any preference for My thought is that history is better classified as "data" than "state". If you agree, would you update the title of the issue to avoid confusion? I'm okay either way, it just seems to me that |
We discussed it and decided against doing this together with 12103. |
I've settled on using See xdg-ninja recommendations for some more opinions. |
Describe the bug
According to the freedesktop basedir specification, configuration and data should be separated.
In case the link stops working, here is the relevant quote:
History is not the configuration of the shell, it's data, so it should be in the data path.
Users still have the option to add
~/.local/share/nushell
to their dotfiles repository if people really want to track it.In order to publish a public dotfiles repository used by others, nushell is currently the only program on my Linux installation that requires specific gitignore file type filters to do so:
If nushell adopts the freedesktop specification by default, we can reduce it to a simple
!/.config/nushell
.How to reproduce
Install nushell and check the contents of the configuration folder.
Expected behavior
config.nu
andenv.nu
in$XDG_CONFIG_HOME/nushell
, defaults to~/.config/nushell
.History files in
$XDG_DATA_HOME/nushell
, defaults to~/.local/share/nushell
.Screenshots
No response
Configuration
Additional context
Edit: While writing this issue, I learned something new: There is also a
$XDG_STATE_HOME
which I wasn't aware of until now and it defaults to~/.local/state
. It specifically mentions "actions history" as a use case. This seems to be the best location for Linux installations.The text was updated successfully, but these errors were encountered: