1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00

fix "from env" newline handling (#1021)

Many (at least the ones I have encountered) env loaders replace "\n"
with a
literal newline character when loading an env variable. I need this
change in
my personal config and I think others would also prefer this default.
This commit is contained in:
Xavier Ruiz 2025-01-25 19:19:36 -05:00 committed by GitHub
parent b42f2bd5c1
commit e245718d30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,6 +6,11 @@ def "from env" []: string -> record {
| split column '#' # remove comments
| get column1
| parse "{key}={value}"
| str trim value -c '"' # unquote values
| update value {
str trim -c '"' | # unquote values
str replace -a "\\n" "\n" # replace `\n` with newline char
str replace -a "\\r" "\r" # replace `\r` with carriage return
str replace -a "\\t" "\t" # replace `\t` with tab
}
| transpose -r -d
}