mirror of
https://github.com/nushell/nushell.git
synced 2025-05-28 14:07:08 +02:00
# Description Due to #14249 loading `default_env.nu` before the user's `env.nu`, variables that were defined there were overriding: * Inherited values * Some values that were set in the Rust code, such as the `NU_LIB_PATH` when set using `--include-path`. This change checks to see if a variable already exists, uses its value if so, and sets the default value otherwise. Note: `ENV_CONVERSIONS` is still "forced" to a default value regardless, as it needs to run reliably. There's probably not much reason to inherit it, but I'm open to the idea if there's a use-case. # User-Facing Changes * Before: Variables that were set in `default_env.nu` always overrode those that were inherited from the parent process or set internally * After: Inherited and internal environment variables will take priority. # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting Will try to find a good place to mention this behavior in the Config chapter updates
58 lines
2.2 KiB
Plaintext
58 lines
2.2 KiB
Plaintext
# Default Nushell Environment Config File
|
|
# These "sensible defaults" are set before the user's `env.nu` is loaded
|
|
#
|
|
# version = "0.100.1"
|
|
|
|
$env.PROMPT_COMMAND = $env.PROMPT_COMMAND? | default {||
|
|
let dir = match (do -i { $env.PWD | path relative-to $nu.home-path }) {
|
|
null => $env.PWD
|
|
'' => '~'
|
|
$relative_pwd => ([~ $relative_pwd] | path join)
|
|
}
|
|
|
|
let path_color = (if (is-admin) { ansi red_bold } else { ansi green_bold })
|
|
let separator_color = (if (is-admin) { ansi light_red_bold } else { ansi light_green_bold })
|
|
let path_segment = $"($path_color)($dir)(ansi reset)"
|
|
|
|
$path_segment | str replace --all (char path_sep) $"($separator_color)(char path_sep)($path_color)"
|
|
}
|
|
|
|
$env.PROMPT_INDICATOR = $env.PROMPT_INDICATOR? | default "> "
|
|
$env.PROMPT_INDICATOR_VI_NORMAL = $env.PROMPT_INDICATOR_VI_NORMAL? | default "> "
|
|
$env.PROMPT_INDICATOR_VI_INSERT = $env.PROMPT_INDICATOR_VI_INSERT? | default ": "
|
|
$env.PROMPT_MULTILINE_INDICATOR = $env.PROMPT_MULTILINE_INDICATOR? | default "::: "
|
|
|
|
$env.PROMPT_COMMAND_RIGHT = $env.PROMPT_COMMAND_RIGHT? | default {||
|
|
# create a right prompt in magenta with green separators and am/pm underlined
|
|
let time_segment = ([
|
|
(ansi reset)
|
|
(ansi magenta)
|
|
(date now | format date '%x %X') # try to respect user's locale
|
|
] | str join | str replace --regex --all "([/:])" $"(ansi green)${1}(ansi magenta)" |
|
|
str replace --regex --all "([AP]M)" $"(ansi magenta_underline)${1}")
|
|
|
|
let last_exit_code = if ($env.LAST_EXIT_CODE != 0) {([
|
|
(ansi rb)
|
|
($env.LAST_EXIT_CODE)
|
|
] | str join)
|
|
} else { "" }
|
|
|
|
([$last_exit_code, (char space), $time_segment] | str join)
|
|
}
|
|
|
|
$env.ENV_CONVERSIONS = {
|
|
"PATH": {
|
|
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
|
|
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
|
|
}
|
|
}
|
|
|
|
$env.NU_LIB_DIRS = $env.NU_LIB_DIRS? | default [
|
|
($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts
|
|
($nu.data-dir | path join 'completions') # default home for nushell completions
|
|
]
|
|
|
|
$env.NU_PLUGIN_DIRS = $env.NU_PLUGIN_DIRS | default [
|
|
($nu.default-config-dir | path join 'plugins') # add <nushell-config-dir>/plugins
|
|
]
|