Repository navigation
Description
Related problem
Related #13670
Goal: The environment variables visible to the user and internal configuration state should match.
It seems to me that an 893-line config (plus 101-line env) is overwhelming to many users, possibly even leaving a bad first impression to some. Regardless, it seems far more "cumbersome" than it should be.
Right now, a user has essentially two choices:
-
Accept an 893-line
config.nuand add to it (either in the file or through other files). In this case, the$env.configwill be populated with the defaults that are in that file, with overrides by the user. The user can introspect the default values by observing, e.g.,$env.config.table.mode.This is currently the only way to achieve the "Goal" above.
-
Run with their own minimal config, but lose the ability to introspect the internal state, other than by reading through
config nu --defaultand comparing what they've changed.
(config.nu example used here, but env.nu behaves the same)
Describe the solution you'd like
Internal defaults are obviously essential, but they don't all need to be exposed in the user's configuration files. For example, see almost every other shell config ;-)
My thoughts:
-
Get rid of the prompt to create
config.nuandenv.nu. Do it automatically if and only if the user is running for the first time (see Only ask user if they want to create a config.nu and env.nu one time #13669) and the$nu.default-config-dirdoesn't exist.- Corollary: If the user deletes either file after first-run, don't regenerate them (a Fish-shell pet peeve I have ;-)
-
Always load
default_env.nuanddefault_config.nuunless the user has started withnu --no-config-file/-n.- Yes, this includes when running with
nu --config <file>ornu --env-config <file>so that the defaults are populated in memory.
- Yes, this includes when running with
-
Only write a minimal
config.nuandenv.nuthat look something like:# Use config.nu to override default $env.config settings, # define (or import) custom commands, or run any other # startup tasks. # # This file is loaded after env.nu and before login.nu # To examine the defaults, run: # config nu --default | nu-highlight
# Use env.nu to add or override environment variables. # This file is loaded before config.nu and login.nu # To examine the defaults, run: # config env --default | nu-highlight
Advantages:
- Users who want to put everything in
config.nucan always just generate it withconfig nu --default | save config.nu(and withenv.nu) - I think that loading
default_env.nuwould also get rid of the hacky "must treat PATH as string in config" issue, since the$env.ENV_CONVERSIONSwould already be in place by the time any user-written code is parsed. - Should be pretty much no impact to startup time since the
default_config.nuet. al. is the same size and parsing-time as the one that is written to disk by default now.- (From thread below) Even if a user duplicates the default config and env on-disk, the parsing and eval time is negligible - only a hair over 1ms on my system.
Describe alternatives you've considered
No response
Additional context and details
Note: About the only reason to not load the default_config.nu/default_env.nu when the user specifies --no-config-file is for performance reasons and testing. If this idea was implemented, it would be nice to have a separate --no-user-config that still loaded default_*.nu but not the on-disk, user files.
Activity
[-]Load `default_config.nu` and `default_env.nu` in all cases[/-][+]Load `default_config.nu` and `default_env.nu` in all cases (except when `--no-config-files` is used)[/+]fdncred commentedon Aug 22, 2024
I guess your proposal means that if a user has a config.nu or env.nu it's additive and specifically meant to change a default. This is similar to people today using the defaults and at the end of config.nu they "source my_config_defaults.nu".
It seems like this could also be a drag on startup times because you not only source the default config and env, but then you source whatever the user has for their config.nu and env.nu. So, if the user has "config nu --default | save config.nu", you're essentially doubling the parsing time, once for default_config.nu and once for config.nu. Am I understanding correctly?
[-]Load `default_config.nu` and `default_env.nu` in all cases (except when `--no-config-files` is used)[/-][+]Simple user configuration[/+][-]Simple user configuration[/-][+]Simplify user configuration[/+]NotTheDr01ds commentedon Aug 22, 2024
Yes, absolutely, and this seems to me to be the "traditional" way of doing things in a shell. Not that I don't think bad traditions should be rethought, but I believe this is a good tradition.
Yup - Caught me before I could get back here to edit that in. I had that idea after I typed it but before I got back to the keyboard. Yes, if a user wants the entire
default_config.nuon the filesystem, it would double parsing time.A couple of thoughts on that though:
But, there may be some other use cases:
If they simply want it for "reference" on the filesystem, then they could save it to
default_config.nuwith no parsing impact. I think most would opt forconfig nu --default(especially if documented in the "sparse" config), but it's an option.Some shells (or at least distributions providing those shells) ship a config with defaults commented out that the user can uncomment to change. This could be done easily with
(Hand-waving around the
$env.configsetting still being monolithic and not able to be uncommented line-by-line, but this would be fixable by changing the default to be "additive", although I'd be curious if there was a performance impact there).NotTheDr01ds commentedon Aug 22, 2024
Also, while we didn't test this scenario while we were looking at it in our
stdlibDiscord chat a while back, parsing and evaluating the default seems to be around 1ms:That's with an on-disk
config.nuandenv.nugenerated in a fresh tempXDG_CONFIG_HOME.fdncred commentedon Aug 22, 2024
I think
nu -conly loads the env.nu file. I don't believe it loads the config.nu.NotTheDr01ds commentedon Aug 22, 2024
Probably right - I didn't check the gist on that.
env.nuis more of an impact - Seems to add 5ms when I test it without-cand just checking the value in the session.Taking a guess that the performance hit for
env.nuis because more lines-of-code get parsed, and several commands loaded into scope as well (e.g.,def create_left_prompt).fdncred commentedon Aug 22, 2024
I'm not sure you can depend on env.nu being slower thought. For instance, my config.nu is much bigger and i do a lot of
useing andsourceing at the end of my config.nu so it's bringing in other files to parse.Also, i've started thinking about relative time and time per byte recently because saying something takes 1ms or 5ms is relative to their system. I've tried to implement this here in my startup-stats custom command. The last 2 columns are new.

In one respect this is still relative because it's only on my windows vm, but at least we're not talking about pure startup time without taking into account if i'm sourcing 1 line or 100k lines.
NotTheDr01ds commentedon Aug 22, 2024
Sure, but we're measuring the impact of double-loading the defaults, right?
Only ask to create config files the first time nu is started (#13857)
Always load default env/config values (#14249)
NotTheDr01ds commentedon Aug 17, 2025
This is now implemented by #13857, #14249, #14435 and others.