mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
Add from env
(#808)
This adds a little command that allows opening .env files as records. My implementation removes comments and works with both quoted and unquoted .env files.
This commit is contained in:
parent
a715b74453
commit
df90d65eec
1 changed files with 11 additions and 0 deletions
11
modules/formats/from-env.nu
Normal file
11
modules/formats/from-env.nu
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Converts a .env file into a record
|
||||
# may be used like this: open .env | load-env
|
||||
# works with quoted and unquoted .env files
|
||||
def "from env" []: string -> record {
|
||||
lines
|
||||
| split column '#' # remove comments
|
||||
| get column1
|
||||
| parse "{key}={value}"
|
||||
| str trim value -c '"' # unquote values
|
||||
| transpose -r -d
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue