Skip to content

Instantly share code, notes, and snippets.

@fdncred
Last active October 23, 2024 22:35
Show Gist options
  • Save fdncred/b87b784f04984dc31a150baed9ad2447 to your computer and use it in GitHub Desktop.
Save fdncred/b87b784f04984dc31a150baed9ad2447 to your computer and use it in GitHub Desktop.
nushell config file loading

Config file loading rules

  1. default_config.nu and default_env.nu refer to the files that are compiled inside of the nushell executable and are also located in our repo.
  2. personal env.nu/config.nu/login.nu refer to the files that are in the $nu.default-config-dir that you have personally edited.
  3. specified config.nu/env.nu refer to files that are specified on the command line with the --config and --env-config command line parameters.

nu

  • ✅ Always reads the nushell standard library
  • ✅ Always reads personal plugin.msgpackz file if it exists
  • ✅ Always reads personal env.nu file if it exists
  • ✅ Always reads personal config.nu file if it exists
  • ❌ Does not read personal login.nu file if it exists
  • ❌ Does not read default_env.nu file
  • ❌ Does not read default_config.nu file

nu -c "ls"

  • ✅ Always reads the nushell standard library
  • ✅ Always reads personal plugin.msgpackz file if it exists
  • ✅ Always reads the default_env.nu file
  • ❌ Does not read default_config.nu file
  • ❌ Does not read personal env.nu file
  • ❌ Does not read personal config.nu file
  • ❌ Does not read personal login.nu file

nu -l -c "ls"

  • ✅ Always reads the nushell standard library
  • ✅ Always reads personal plugin.msgpackz file if it exists
  • ✅ Always reads personal env.nu file if it exists
  • ✅ Always reads personal config.nu file if it exists
  • ✅ Always reads personal login.nu file if it exists
  • ❌ Does not read default_env.nu file
  • ❌ Does not read default_config.nu file

nu -l -c "ls" --config foo_config.nu

  • ✅ Always reads the nushell standard library
  • ✅ Always reads personal plugin.msgpackz file if it exists
  • ✅ Always reads personal env.nu file if it exists
  • ✅ Always reads specified config file if it exists
  • ✅ Always reads personal login.nu file if it exists
  • ❌ Does not read default_env.nu file
  • ❌ Does not read default_config.nu file

nu -l -c "ls" --config foo_config.nu --env-config foo_env.nu

  • ✅ Always reads the nushell standard library
  • ✅ Always reads personal plugin.msgpackz file if it exists
  • ✅ Always reads specified env.nu file if it exists
  • ✅ Always reads specified config.nu file if it exists
  • ✅ Always reads personal login.nu file if it exists
  • ❌ Does not read default_env.nu file
  • ❌ Does not read default_config.nu file

nu -n -l -c "ls"

  • ✅ Always reads the nushell standard library
  • ❌ Does not read personal plugin.msgpackz file
  • ❌ Does not read personal env.nu file
  • ❌ Does not read personal config.nu file
  • ❌ Does not read personal login.nu file
  • ❌ Does not read default_env.nu file (seems odd to me that it's not loading deafult_env.nu)
  • ❌ Does not read default_config.nu file (seems odd to me that it's not loading deafult_config.nu)

nu test.nu

  • ✅ Always reads the nushell standard library
  • ✅ Always reads personal plugin.msgpackz file if it exists
  • ❌ Does not read personal env.nu file
  • ❌ Does not read personal config.nu file
  • ❌ Does not read personal login.nu file
  • ✅ Always reads default_env.nu file
  • ❌ Does not read default_config.nu file

nu --config foo_config.nu --env-config foo_env.nu test.nu

  • ✅ Always reads the nushell standard library
  • ✅ Always reads personal plugin.msgpackz file if it exists
  • ✅ Always reads specified env.nu file if it exists
  • ✅ Always reads specified config.nu file if it exists
  • ❌ Does not read personal login.nu file
  • ❌ Does not read default_env.nu file
  • ❌ Does not read default_config.nu file

nu -n --no-std-lib

  • ❌ Does not read the nushell standard library
  • ❌ Does not read personal plugin.msgpackz file
  • ❌ Does not read personal env.nu file
  • ❌ Does not read personal config.nu file
  • ❌ Does not read personal login.nu file
  • ❌ Does not read default_env.nu file
  • ❌ Does not read default_config.nu file

special case nu

When nushell is initially launched, and there is no config directory created yet, nushell will prompt you to create one and add the default_config.nu and default_env.nu in that folder. If you say no to this, a nushell folder will be created anyway without putting any config files in that folder and a history.txt file will be placed in that folder. Once that is done, these files are sourced. Each time you start nushell, and there is no config.nu or env.nu in the config folder, the default_config.nu and default_env.nu are sourced and you can see the settings in $env.

  • ✅ Always reads the nushell standard library
  • ❌ Always reads personal plugin.msgpackz file if it exists
  • ❌ Always reads personal env.nu file if it exists
  • ❌ Always reads personal config.nu file if it exists
  • ❌ Does not read personal login.nu file if it exists
  • ✅ Always reads default_env.nu file
  • ✅ Always reads default_config.nu file

I just updated this 2024-09-26 nushell version 0.98.1

@amtoine
Copy link

amtoine commented Jun 29, 2024

if the Rust defaults and the default config files, differ, that's a bug, right?

i think that, when no custom config files are loaded, the Rust defaults are used by construction of the Nushell code and thus it's the same as "loading the default config files".
it's been a while i haven't looked at the code for this, so i might be wrong 😌

@fdncred
Copy link
Author

fdncred commented Jun 29, 2024

if the Rust defaults and the default config files, differ, that's a bug, right?

probably so

i think that, when no custom config files are loaded, the Rust defaults are used by construction of the Nushell code and thus it's the same as "loading the default config files".
it's been a while i haven't looked at the code for this, so i might be wrong 😌

This is the way it theoretically should work but it doesn't. Last I looked, the prompt is different and NU_LIB_DIRS (and maybe other nu.env settings) are different. So, at a minimum those things are different. The config.nu may have some things that need to be updated too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment