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:
parent
5869e0b529
commit
90eb75d97f
1 changed files with 6 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue