MCPcopy
hub / github.com/direnv/direnv / ToShell

Method ToShell

internal/cmd/env_diff.go:87–102  ·  view source on GitHub ↗

ToShell applies the env diff as a set of commands that are understood by the target `shell`. The outputted string is then meant to be evaluated in the target shell.

(shell Shell)

Source from the content-addressed store, hash-verified

85// the target `shell`. The outputted string is then meant to be evaluated in
86// the target shell.
87func (diff *EnvDiff) ToShell(shell Shell) (string, error) {
88 e := make(ShellExport)
89
90 for key := range diff.Prev {
91 _, ok := diff.Next[key]
92 if !ok {
93 e.Remove(key)
94 }
95 }
96
97 for key, value := range diff.Next {
98 e.Add(key, value)
99 }
100
101 return shell.Export(e)
102}
103
104// Patch applies the diff to the given env and returns a new env with the
105// changes applied.

Callers

nothing calls this directly

Calls 3

RemoveMethod · 0.80
AddMethod · 0.80
ExportMethod · 0.65

Tested by

no test coverage detected