From 8fe6dd2dcf7ab651b327a0cc12d17aaae4b9b8e5 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sun, 2 Apr 2023 19:10:34 +0200 Subject: [PATCH] feat(template): add parsed SHLVL --- src/platform/shell.go | 6 ++++++ website/docs/configuration/templates.mdx | 1 + 2 files changed, 7 insertions(+) diff --git a/src/platform/shell.go b/src/platform/shell.go index d4aea9fb..08ac2836 100644 --- a/src/platform/shell.go +++ b/src/platform/shell.go @@ -189,6 +189,7 @@ type TemplateCache struct { OS string WSL bool PromptCount int + SHLVL int Segments SegmentsCache sync.RWMutex @@ -824,6 +825,11 @@ func (env *Shell) TemplateCache() *TemplateCache { tmplCache.OS = env.Platform() } + val := env.Getenv("SHLVL") + if shlvl, err := strconv.Atoi(val); err == nil { + tmplCache.SHLVL = shlvl + } + env.tmplCache = tmplCache return tmplCache } diff --git a/website/docs/configuration/templates.mdx b/website/docs/configuration/templates.mdx index 6a4c59d6..6328107f 100644 --- a/website/docs/configuration/templates.mdx +++ b/website/docs/configuration/templates.mdx @@ -20,6 +20,7 @@ offers a few standard properties to work with. | `.Folder` | `string` | the current working folder | | `.Shell` | `string` | the current shell name | | `.ShellVersion` | `string` | the current shell version | +| `.SHLVL` | `int` | the current shell level | | `.UserName` | `string` | the current user name | | `.HostName` | `string` | the host name | | `.Code` | `int` | the last exit code |