mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-07-31 14:17:45 +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:
parent
b42f2bd5c1
commit
e245718d30
1 changed files with 8 additions and 3 deletions
|
@ -2,10 +2,15 @@
|
|||
# may be used like this: open .env | load-env
|
||||
# works with quoted and unquoted .env files
|
||||
def "from env" []: string -> record {
|
||||
lines
|
||||
lines
|
||||
| split column '#' # remove comments
|
||||
| get column1
|
||||
| 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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue