mirror of
https://github.com/nushell/nu_scripts.git
synced 2024-08-16 08:50:31 +03: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
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…
Reference in New Issue
Block a user