From adf97352d0887d4888958b42566fa14d390cd154 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Mon, 6 May 2024 20:35:44 +0200 Subject: [PATCH] feat(notice): disable from configuration resolves #4902 --- src/cli/enable.go | 1 + src/cli/init.go | 11 +++++++++++ src/engine/config.go | 1 + src/upgrade/notice.go | 9 +++++---- themes/schema.json | 12 ++++++++++++ website/docs/configuration/general.mdx | 1 + 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/cli/enable.go b/src/cli/enable.go index 684c5d19..aa83be59 100644 --- a/src/cli/enable.go +++ b/src/cli/enable.go @@ -55,6 +55,7 @@ func toggleFeature(cmd *cobra.Command, feature string, enable bool) { env.Cache().Delete(upgrade.CACHEKEY) return } + env.Cache().Set(upgrade.CACHEKEY, "disabled", -1) default: _ = cmd.Help() diff --git a/src/cli/init.go b/src/cli/init.go index c9039189..9ff287b1 100644 --- a/src/cli/init.go +++ b/src/cli/init.go @@ -6,6 +6,7 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/engine" "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/shell" + "github.com/jandedobbeleer/oh-my-posh/src/upgrade" "github.com/spf13/cobra" ) @@ -63,11 +64,14 @@ func runInit(shellName string) { } env.Init() defer env.Close() + cfg := engine.LoadConfig(env) + shell.Transient = cfg.TransientPrompt != nil shell.ErrorLine = cfg.ErrorLine != nil || cfg.ValidLine != nil shell.Tooltips = len(cfg.Tooltips) > 0 shell.ShellIntegration = cfg.ShellIntegration + for i, block := range cfg.Blocks { // only fetch cursor position when relevant if !cfg.DisableCursorPositioning && (i == 0 && block.Newline) { @@ -77,11 +81,18 @@ func runInit(shellName string) { shell.RPrompt = true } } + + // allow overriding the upgrade notice from the config + if cfg.DisableNotice { + env.Cache().Set(upgrade.CACHEKEY, "disabled", -1) + } + if printOutput { init := shell.PrintInit(env) fmt.Print(init) return } + init := shell.Init(env) fmt.Print(init) } diff --git a/src/engine/config.go b/src/engine/config.go index 378cffa3..a96b1ce4 100644 --- a/src/engine/config.go +++ b/src/engine/config.go @@ -51,6 +51,7 @@ type Config struct { Var map[string]any `json:"var,omitempty" toml:"var,omitempty"` DisableCursorPositioning bool `json:"disable_cursor_positioning,omitempty" toml:"disable_cursor_positioning,omitempty"` PatchPwshBleed bool `json:"patch_pwsh_bleed,omitempty" toml:"patch_pwsh_bleed,omitempty"` + DisableNotice bool `json:"disable_notice,omitempty" toml:"disable_notice,omitempty"` // Deprecated OSC99 bool `json:"osc99,omitempty" toml:"osc99,omitempty"` diff --git a/src/upgrade/notice.go b/src/upgrade/notice.go index 371b2b66..5564e797 100644 --- a/src/upgrade/notice.go +++ b/src/upgrade/notice.go @@ -59,15 +59,16 @@ func Latest(env platform.Environment) (string, error) { // // The upgrade check is only performed every other week. func Notice(env platform.Environment) (string, bool) { - // never validate when we install using the Windows Store - if env.Getenv("POSH_INSTALLER") == "ws" { - return "", false - } // do not check when last validation was < 1 week ago if _, OK := env.Cache().Get(CACHEKEY); OK { return "", false } + // never validate when we install using the Windows Store + if env.Getenv("POSH_INSTALLER") == "ws" { + return "", false + } + latest, err := Latest(env) if err != nil { return "", false diff --git a/themes/schema.json b/themes/schema.json index f9e249b3..c85678d8 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -4449,6 +4449,18 @@ "description": "https://ohmyposh.dev/docs/configuration/general#general-settings", "default": "" }, + "disable_notice": { + "type": "boolean", + "title": "Disable Upgrade Notice", + "description": "https://ohmyposh.dev/docs/configuration/title#general-settings", + "default": false + }, + "patch_pwsh_bleed": { + "type": "boolean", + "title": "Patch PowerShell Color Bleed", + "description": "https://ohmyposh.dev/docs/configuration/title#general-settings", + "default": false + }, "console_title_template": { "type": "string", "title": "Console Title Template", diff --git a/website/docs/configuration/general.mdx b/website/docs/configuration/general.mdx index e6c2cc6c..6a33108f 100644 --- a/website/docs/configuration/general.mdx +++ b/website/docs/configuration/general.mdx @@ -136,6 +136,7 @@ For example, the following is a valid `--config` flag: | `shell_integration` | `boolean` | enable shell integration using FinalTerm's OSC sequences. Works in bash, cmd (Clink v1.14.25+), fish, powershell and zsh | | `disable_cursor_positioning` | `boolean` | disable fetching the cursor position in bash and zsh in case of unwanted side-effects | | `patch_pwsh_bleed` | `boolean` | patch a PowerShell bug where the background colors bleed into the next line at the end of the buffer (can be removed when [this][pwsh-bleed] is merged) | +| `disable_notice` | `boolean` | disable the upgrade notice | ### JSON Schema Validation