diff --git a/src/engine/new.go b/src/engine/new.go index fea6ac6c..13732a43 100644 --- a/src/engine/new.go +++ b/src/engine/new.go @@ -17,6 +17,7 @@ func New(flags *platform.Flags) *Engine { env.Init() cfg := LoadConfig(env) env.Var = cfg.Var + flags.HasTransient = cfg.TransientPrompt != nil ansiWriter := &ansi.Writer{ TerminalBackground: shell.ConsoleBackgroundColor(env, cfg.TerminalBackground), diff --git a/src/platform/shell.go b/src/platform/shell.go index 0301e2d8..605409c2 100644 --- a/src/platform/shell.go +++ b/src/platform/shell.go @@ -67,6 +67,7 @@ type Flags struct { Manual bool Plain bool Primary bool + HasTransient bool PromptCount int Cleared bool Version string @@ -743,12 +744,22 @@ func (env *Shell) Cache() Cache { return env.fileCache } -func (env *Shell) Close() { - defer env.Trace(time.Now()) +func (env *Shell) saveTemplateCache() { + // only store this when in a primary prompt + // and when we have a transient prompt in the config + canSave := env.CmdFlags.Primary && env.CmdFlags.HasTransient + if !canSave { + return + } templateCache, err := json.Marshal(env.TemplateCache()) if err == nil { env.fileCache.Set(TEMPLATECACHE, string(templateCache), 1440) } +} + +func (env *Shell) Close() { + defer env.Trace(time.Now()) + env.saveTemplateCache() env.fileCache.Close() }