nushell/src
Douglas d68c3ec89a
Only ask to create config files the first time nu is started (#13857)
# 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.

4. The next time `nu` is run, we check if the directory exists.  If so:
5. Do not prompt user to create any missing files **(New Behavior)**
6. `$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

7. `$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.
2024-09-26 13:54:42 -05:00
..
command.rs Error on non-zero exit statuses (#13515) 2024-09-07 06:44:26 +00:00
config_files.rs Only ask to create config files the first time nu is started (#13857) 2024-09-26 13:54:42 -05:00
ide.rs Error on non-zero exit statuses (#13515) 2024-09-07 06:44:26 +00:00
logger.rs Add options for filtering the log output from nu (#13044) 2024-06-05 16:42:55 +08:00
main.rs Set current working directory at startup (#12953) 2024-09-25 13:04:26 -05:00
README.md Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
run.rs Only ask to create config files the first time nu is started (#13857) 2024-09-26 13:54:42 -05:00
signals.rs fix: relay Signals reset to plugins (#13510) 2024-08-06 03:35:40 -07:00
terminal.rs Deduplicate nix dependency versions (#12307) 2024-03-27 16:43:37 +01:00
test_bins.rs Set current working directory at startup (#12953) 2024-09-25 13:04:26 -05:00

Nushell REPL

This directory contains the main Nushell REPL (read eval print loop) as part of the CLI portion of Nushell, which creates the nu binary itself.

Current versions of the nu binary will use the Nu argument parsing logic to parse the commandline arguments passed to nu, leaving the logic here to be a thin layer around what the core libraries.