Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify handling of .env files #941

Merged
merged 1 commit into from May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 5 additions & 8 deletions README.md
Expand Up @@ -18,14 +18,11 @@ current directory.

## How it works

Before each prompt, direnv checks for the existence of a `.envrc` or `.env`
file in the current and parent directories. If the file exists (and is
authorized), it is loaded into a **bash** sub-shell and all exported
variables are then captured by direnv and then made available to the current
shell.

If both `.envrc` and `.env` files exists, the `.envrc` will always be chosen
first.
Before each prompt, direnv checks for the existence of a `.envrc` file (and
[optionally](man/direnv.toml.1.md#load_dotenv) a `.env` file) in the current
and parent directories. If the file exists (and is authorized), it is loaded
into a **bash** sub-shell and all exported variables are then captured by
direnv and then made available to the current shell.

It supports hooks for all the common shells like bash, zsh, tcsh and fish.
This allows project-specific environment variables without cluttering the
Expand Down
5 changes: 4 additions & 1 deletion internal/cmd/cmd_allow.go
Expand Up @@ -65,7 +65,10 @@ func cmdAllowAction(env Env, args []string, config *Config) (err error) {
if err != nil {
return err
} else if rc == nil {
return fmt.Errorf(".envrc or .env file not found")
if config.LoadDotenv {
return fmt.Errorf(".envrc or .env file not found")
}
return fmt.Errorf(".envrc file not found")
}
return rc.Allow()
}
5 changes: 4 additions & 1 deletion internal/cmd/cmd_deny.go
Expand Up @@ -35,7 +35,10 @@ func cmdDenyAction(env Env, args []string, config *Config) (err error) {
if err != nil {
return err
} else if rc == nil {
return fmt.Errorf(".envrc or .env file not found")
if config.LoadDotenv {
return fmt.Errorf(".envrc or .env file not found")
}
return fmt.Errorf(".envrc file not found")
}
return rc.Deny()
}
2 changes: 1 addition & 1 deletion man/direnv.toml.1
Expand Up @@ -54,7 +54,7 @@ If set to \fB\fCtrue\fR, stdin is disabled (redirected to /dev/null) during the

.SS \fB\fCload_dotenv\fR
.PP
Also look for and load \fB\fC\&.env\fR files on top of the \fB\fC\&.envrc\fR files.
Also look for and load \fB\fC\&.env\fR files on top of the \fB\fC\&.envrc\fR files. If both \fB\fC\&.envrc\fR and \fB\fC\&.env\fR files exist, the \fB\fC\&.envrc\fR will always be chosen first.

.SS \fB\fCstrict_env\fR
.PP
Expand Down
2 changes: 1 addition & 1 deletion man/direnv.toml.1.md
Expand Up @@ -44,7 +44,7 @@ If set to `true`, stdin is disabled (redirected to /dev/null) during the `.envrc

### `load_dotenv`

Also look for and load `.env` files on top of the `.envrc` files.
Also look for and load `.env` files on top of the `.envrc` files. If both `.envrc` and `.env` files exist, the `.envrc` will always be chosen first.

### `strict_env`

Expand Down