Skip to content

Commit

Permalink
feat: hide env diff (#1234)
Browse files Browse the repository at this point in the history
Some users don't want to see what environment variables have changed in
the shell.

Fixes part of #68
  • Loading branch information
zimbatm committed Feb 1, 2024
1 parent a18650e commit bd52882
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/cmd/cmd_export.go
Expand Up @@ -100,13 +100,14 @@ func exportCommand(currentEnv Env, args []string, config *Config) (err error) {
}
}

if out := diffStatus(previousEnv.Diff(newEnv)); out != "" {
if out := diffStatus(previousEnv.Diff(newEnv)); out != "" && !config.HideEnvDiff {
logStatus(currentEnv, "export %s", out)
}

diffString := currentEnv.Diff(newEnv).ToShell(shell)
logDebug("env diff %s", diffString)
fmt.Print(diffString)

return
}

Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/config.go
Expand Up @@ -23,6 +23,7 @@ type Config struct {
BashPath string
RCFile string
TomlPath string
HideEnvDiff bool
DisableStdin bool
StrictEnv bool
LoadDotenv bool
Expand Down Expand Up @@ -54,6 +55,7 @@ type tomlGlobal struct {
SkipDotenv bool `toml:"skip_dotenv"` // deprecated, use load_dotenv
LoadDotenv bool `toml:"load_dotenv"`
WarnTimeout *tomlDuration `toml:"warn_timeout"`
HideEnvDiff bool `toml:"hide_env_diff"`
}

type tomlWhitelist struct {
Expand Down Expand Up @@ -138,6 +140,8 @@ func LoadConfig(env Env) (config *Config, err error) {
return
}

config.HideEnvDiff = tomlConf.HideEnvDiff

for _, path := range tomlConf.Whitelist.Prefix {
config.WhitelistPrefix = append(config.WhitelistPrefix, expandTildePath(path))
}
Expand Down
5 changes: 5 additions & 0 deletions man/direnv.toml.1.md
Expand Up @@ -63,6 +63,11 @@ Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
This feature is disabled if the duration is lower or equal to zero.
Will be overwritten if the environment variable `DIRENV_WARN_TIMEOUT` is set to any of the above values.

### `hide_env_diff`

Set to `true` to hide the diff of the environment variables when loading the
`.envrc`. Defaults to `false`.

## [whitelist]

Specifying whitelist directives marks specific directory hierarchies or specific directories as "trusted" -- direnv will evaluate any matching .envrc files regardless of whether they have been specifically allowed. **This feature should be used with great care**, as anyone with the ability to write files to that directory (including collaborators on VCS repositories) will be able to execute arbitrary code on your computer.
Expand Down

0 comments on commit bd52882

Please sign in to comment.