mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 07:07:46 +00:00
Deprecate the nu_scripts
version of stdlib-candidate
(#1042)
Deprecates the existing `stdlib-candidate` directories in `nu_scripts` since `std-rfc` has now transitioned to the main repo. Updates readme and renamed directories.
This commit is contained in:
parent
a31f8490fb
commit
5869e0b529
53 changed files with 18 additions and 40 deletions
|
@ -0,0 +1,37 @@
|
|||
# Gracefully set an environment variable or merge a nested option.
|
||||
#
|
||||
# Examples:
|
||||
# Set $env.NUPM_HOME
|
||||
# > set-env NUPM_HOME $'($nu.home-path)/.local/share/nupm'
|
||||
#
|
||||
# Add to $env.NU_LIB_DIRS
|
||||
# > set-env --append NU_LIB_DIRS $'($env.NUPM_HOME)/modules'
|
||||
#
|
||||
# Set a nested config option
|
||||
# > set-env config.filesize.metric true
|
||||
#
|
||||
# Add a config hook
|
||||
# > set-env -a config.hooks.pre_prompt 'ellie | print'
|
||||
export def --env main [
|
||||
field: cell-path # The environment variable name or nested option cell path
|
||||
value: any # The value to set or append
|
||||
--append (-a) # Append to the previous value or wrap in a new list
|
||||
]: nothing -> nothing {
|
||||
def 'get or' [default field] {
|
||||
get --ignore-errors $field | default $default
|
||||
}
|
||||
let value = if $append {
|
||||
$env | get or [] $field | append $value
|
||||
} else {
|
||||
$value
|
||||
}
|
||||
let field = $field | to text | split row .
|
||||
let value = match $field {
|
||||
[_] => $value
|
||||
[$root, ..$field] => {
|
||||
let field = $field | into cell-path
|
||||
$env | get or {} $root | upsert $field $value
|
||||
}
|
||||
}
|
||||
load-env { ($field | first): $value }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue