envdir/README.md

48 lines
1.1 KiB
Markdown

# envdir
A Go clone of the [daemontools](https://cr.yp.to/daemontools.html) `envdir`
program.
## Install
```
go install sneak.berlin/go/envdir@latest
```
## Usage
```
envdir dir child [args...]
```
`envdir` sets various environment variables as specified by files in `dir`,
then runs `child` with the given arguments.
If `dir` contains a file named `FOO` whose first line is `bar`, `envdir`
sets the environment variable `FOO` to `bar`, then runs `child`.
### Rules
- Each file in `dir` corresponds to one environment variable. The filename
is the variable name and the first line of the file is the value.
- If a file is empty, the corresponding variable is **unset**.
- NUL bytes (`\0`) in file contents are replaced with newlines.
- Trailing spaces and tabs are stripped from the value.
- Lines after the first newline are ignored.
- Subdirectories and files with `=` in the name are skipped.
- Exit code is **111** if `envdir` encounters an error.
## Example
```
$ mkdir /tmp/env
$ echo -n "production" > /tmp/env/APP_ENV
$ echo -n "localhost:5432" > /tmp/env/DB_HOST
$ envdir /tmp/env printenv APP_ENV
production
```
## License
MIT