Skip to content

Commit df90d65

Browse files
authored
Add from env (nushell#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.
1 parent a715b74 commit df90d65

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

modules/formats/from-env.nu

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Converts a .env file into a record
2+
# may be used like this: open .env | load-env
3+
# works with quoted and unquoted .env files
4+
def "from env" []: string -> record {
5+
lines
6+
| split column '#' # remove comments
7+
| get column1
8+
| parse "{key}={value}"
9+
| str trim value -c '"' # unquote values
10+
| transpose -r -d
11+
}

0 commit comments

Comments
 (0)