Skip to content

Only ask to create config files the first time nu is started - #13857

Merged
fdncred merged 4 commits into
nushell:mainfrom
NotTheDr01ds:config-ask-once
Sep 26, 2024
Merged

fdncred merged 4 commits into
nushell:mainfrom
NotTheDr01ds:config-ask-once

Conversation

@NotTheDr01ds

@NotTheDr01ds NotTheDr01ds commented Sep 17, 2024 •

Copy link
Copy Markdown
Contributor

Description

Implements #13669

When nu is started for the first time, the directory represented by $nu.default-config-dir typically will not exist. In this case, Nushell will create the directory. It will then detect that either or both config.nu/env.nu don't exist and offer to create them.

(Existing behavior) If the user declines, the directory will still be created (since the history file lives there as well). The default_config.nu and default_env.nu will be loaded.

On subsequent launches, as long as the config directory continues to exist, the user will not be prompted to recreate the config files. Nushell will behave as if the user answered "N" to the prompt in that default_config.nu and default_env.nu will be used.

The user can still create a config.nu or env.nu at any point, and that will be used. In that case, default_config.nu and/or default_env.nu will no longer be loaded (unless and until #13671 is implemented).

User-Facing Changes

User will no longer be prompted to create config files if they are missing so long as the config directory exists.

Before this change:

  1. Nushell starts for the first time

  2. The directory where config files are stored does not exist

  3. The config files do not exist

    • User is asked whether they want to create env.nu

      • User says, "Y", default_env.nu is copied to the directory as env.nu (and directory is created if needed)
      • User says, "n", default_env.nu is loaded, but no file on the filesystem is created.
    • User is asked whether they want to create config.nu

      • User says, "Y", default_config.nu is copied to the directory as config.nu (and directory is created if needed)
      • User says, "n", default_config.nu is loaded, but no file on the filesystem is created.
  4. The next time nu is run, if either file is missing, the user will be prompted again for that file.

After this change:

Steps 1 - 3 remains the same.

  1. The next time nu is run, we check if the directory exists. If so:

  2. Do not prompt user to create any missing files (New Behavior)

  3. $nu.default-config-dir/env.nu exists?

    • Yes? Use it. (Normal behavior)
    • No? Evaluate default_env.nu. (Normal behavior)
    • No file is created on the filesystem
  4. $nu.default-config-dir/config.nu exists?

    • Yes? Use it. (Normal behavior)
    • No? Evaluate default_config.nu (Normal behavior)
    • No file is created on the filesystem

Tests + Formatting

  • 🟢 toolkit fmt
  • 🟢 toolkit clippy
  • 🟢 toolkit test
  • 🟢 toolkit test stdlib

After Submitting

This behavior isn't currently mentioned in the configuration doc. I'll probably hold off on changing anything in the doc until #13671 is implemented. Regardless, given the timing, this won't make it into a release for at least 4 weeks.

@NotTheDr01ds NotTheDr01ds added the A:configuration Issue related to nu's configuration label Sep 17, 2024
@NotTheDr01ds
NotTheDr01ds force-pushed the config-ask-once branch 2 times, most recently from c601c29 to fb15beb Compare September 17, 2024 19:08
@fdncred

fdncred commented Sep 25, 2024

Copy link
Copy Markdown
Contributor

i've read this a few times and would really benefit from a "before this PR this happens" and "after this PR this happens" sections.

after this pr, if the config folder exists, and there are no config files, do the default_config.nu and default_env.nu get loaded?

@NotTheDr01ds

Copy link
Copy Markdown
Contributor Author

@fdncred Added an overview of the algorithm to the "User facing changes".

That said, the default_<file>.nu behavior in those cases is really unchanged. If a config.nu doesn't exist, then default_config.nu is used instead (and with env). This PR doesn't really change that part; it just makes sure to only ask the user whether they want to create the config.nu and env.nu one time.

@fdncred

fdncred commented Sep 25, 2024

Copy link
Copy Markdown
Contributor

Thanks. So, with this change, if neither config.nu nor env.nu exists in the config folder, the default_config.nu and default_env.nu are used on every startup. That's different than before. Sounds like that would only happen the first time prior to this PR.

@NotTheDr01ds

NotTheDr01ds commented Sep 25, 2024 •

Copy link
Copy Markdown
Contributor Author

Hmm - Still not really a change in that regard. Think of it this way:

Before

  • Ask every time. If the user says "n" every time then ...
  • Because there is no env.nu and/or config.nu -default_env.nu and/or default_config.nu are loaded instead.

After

  • Ask once. If the user says "n" once, remember that selection (change)
  • Because there is no env.nu and/or config.nu -default_env.nu and/or default_config.nu are loaded instead. (no change)

@fdncred

fdncred commented Sep 26, 2024

Copy link
Copy Markdown
Contributor

right but the difference is that before it was notifying/nagging the user to create the config files. now it's just silently sourcing the default config files.

@NotTheDr01ds

Copy link
Copy Markdown
Contributor Author

Fair enough. It's a change in that regard, yes.

I'm not sure the user was ever aware of the behind-the-scenes of what happened when they said "No", though. It took us long enough to figure out that the default config files were being used in that case. Until recently, we thought it was using the Rust defaults in that case (like it does in every other).

Is there any downside to using default_xxx.nu in this particular case? Of course, you know I'd like to work on expanding their use once this lands ;-).

@fdncred

fdncred commented Sep 26, 2024

Copy link
Copy Markdown
Contributor

ya, my gist of what loads when probably needs to be updated.

let's give this a try and see how it goes since we're pretty early in the release cycle. Thanks!

@fdncred
fdncred merged commit d68c3ec into nushell:main Sep 26, 2024
@fdncred

fdncred commented Sep 26, 2024

Copy link
Copy Markdown
Contributor

@NotTheDr01ds
NotTheDr01ds deleted the config-ask-once branch September 26, 2024 19:55
@hustcer hustcer added this to the v0.99.0 milestone Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:configuration Issue related to nu's configuration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants