From bd52882f30936bb23290d9663e857e4f8b761b7f Mon Sep 17 00:00:00 2001 From: Jonas Chevalier Date: Thu, 1 Feb 2024 14:46:12 +0100 Subject: [PATCH] feat: hide env diff (#1234) Some users don't want to see what environment variables have changed in the shell. Fixes part of #68 --- internal/cmd/cmd_export.go | 3 ++- internal/cmd/config.go | 4 ++++ man/direnv.toml.1.md | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/cmd/cmd_export.go b/internal/cmd/cmd_export.go index 68ed5dff0..30dfdeee1 100644 --- a/internal/cmd/cmd_export.go +++ b/internal/cmd/cmd_export.go @@ -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 } diff --git a/internal/cmd/config.go b/internal/cmd/config.go index 79c6c9c5c..ea5b7d1dd 100644 --- a/internal/cmd/config.go +++ b/internal/cmd/config.go @@ -23,6 +23,7 @@ type Config struct { BashPath string RCFile string TomlPath string + HideEnvDiff bool DisableStdin bool StrictEnv bool LoadDotenv bool @@ -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 { @@ -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)) } diff --git a/man/direnv.toml.1.md b/man/direnv.toml.1.md index f9144606a..4a1767e3e 100644 --- a/man/direnv.toml.1.md +++ b/man/direnv.toml.1.md @@ -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.