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

Fix from env custom command (#1045)

Fix `from env` custom command

#### Description

This pull request addresses issues with the `from env` custom command in
the Nushell script, improving the handling and sanitization of parsed
environment variable values. The main focus of this update is to enhance
the parsing behavior to handle edge cases and ensure proper formatting
of output.
This commit is contained in:
Justin Ma 2025-02-13 20:18:13 +08:00 committed by GitHub
parent 5869e0b529
commit 90eb75d97f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,10 +7,12 @@ def "from env" []: string -> record {
| get column1
| parse "{key}={value}"
| 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
str trim # Trim whitespace between value and inline comments
| str trim -c '"' # unquote double-quoted values
| str trim -c "'" # unquote single-quoted 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
}