Skip to content

Inconsistency in how/when $env.config and other variables are populated #13670

@NotTheDr01ds

Description

@NotTheDr01ds

Describe the bug

  1. When starting with nu --no-config-file/-n:

    • the Nushell defaults for $env.config are not populated into the environment. The defaults are still in play if they haven't been overwritten by a corresponding variable in the environment, but they cannot be introspected by the user with, e.g., $env.config.color_config.
    • $env.NU_LIB_DIRS is populated with a default, even if it was not present in the parent process
    • $env.PROMPT_ variables are not populated by default, but may be inherited from the parent process.
  2. When starting with an empty or user-generated config.nu or env.nu the default config values are also not populated into the environment. Same rules as above apply.

  3. However, when starting nu when no env.nu and/or config.nu exists, Nushell will ask the user if they want to create one. If the user responds with "n"/No, then there is no file, but $env.config is fully populated with the defaults (when there is no config.nu), as are $env.PROMPT_* variables when there is no env.nu.

How to reproduce

Best to run all of these from a parent Bash process where there are no Nushell environment variables set. For Windows users, WSL makes this pretty easy by starting with wsl ~ -e /usr/bin/bash.

  1. Scenario 1 above

    nu -n
    $env.config
    # => Result
    $env.config                                                                                                                                                                                                                 
    08/22/2024 09:34:23 AM
    Error: nu::shell::column_not_found
    
      × Cannot find column 'config'
       ╭─[entry #1:1:1]
     1$env.config
       · ──┬─ ───┬──
       ·   │     ╰── cannot find column 'config'
       ·   ╰── value originates here
       ╰────
    
    $env.NU_LIB_DIRS
    # => Result
    ╭───┬────────────────────────────────────────────╮
    │ 0/home/ntd/.config/nushell/scripts          │
    │ 1 │ /home/ntd/.local/share/nushell/completions │
    ╰───┴────────────────────────────────────────────╯
    
  2. Scenario 2 above:

    Important: Run through Scenario 3 to start, but don't exit Nushell when finished.

    touch ($nu.default-config-dir | path join "config.nu")
    # Exit Nushell, don't exit Bash so that the XDG_CONFIG_HOME is still in play
    nu
    # Get prompt only for env.nu - Say "no"
    $env.config.color_config.block 
    # => Result
    Error: nu::shell::column_not_found
    
      × Cannot find column 'config'
       ╭─[entry #1:1:1]
     1$env.config.color_config.block
       · ──┬─ ───┬──
       ·   │     ╰── cannot find column 'config'
       ·   ╰── value originates here
       ╰────
    
    # default_env.nu is still in play
    view source ($env.PROMPT_COMMAND)
    # => {|| create_left_prompt }
  3. Scenario 3 above:

    # from bash
    export XDG_CONFIG_HOME=$(mktemp -d)
    nu
    # Say n to both prompts
    $env.config.color_config.block
    # => white
    view source ($env.PROMPT_COMMAND)
    # => {|| create_left_prompt }
    view source create_left_prompt
    # => Prompt function is defined
    view files | find default
    # =>
    ╭───┬───────────────────┬───────┬────────┬───────╮
    │ # │     filename      │ start │  end   │ size  │
    ├───┼───────────────────┼───────┼────────┼───────┤
    │ 0 │ default_env.nu    │ 85633899104277 │
    │ 1 │ default_config.nu │ 8996711977329806 │
    ╰───┴───────────────────┴───────┴────────┴───────╯

Expected behavior

My ideal scenario is more of an enhancement request that I'll open separately, but I would expect more consistency in the way that default_config.nu and default_env.nu are loaded.

Screenshots

No response

Configuration

key value
version 0.97.1
major 0
minor 97
patch 1
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.80.1 (3f5fd8dd4 2024-08-06)
rust_channel stable-x86_64-unknown-linux-gnu
cargo_version cargo 1.80.1 (376290515 2024-07-16)
build_time 2024-08-21 13:13:11 -04:00
build_rust_channel release
allocator mimalloc
features default, sqlite, system-clipboard, trash
installed_plugins formats 0.96.1, inc 0.96.1

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:configurationIssue related to nu's configurationcategory:inconsistent-behaviorBehavior between different commands or types inconsistent/unexpected

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions