feat(notice): disable from configuration

resolves #4902
This commit is contained in:
Jan De Dobbeleer 2024-05-06 20:35:44 +02:00 committed by Jan De Dobbeleer
parent 4c6cb5ad3d
commit adf97352d0
6 changed files with 31 additions and 4 deletions

View file

@ -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()

View file

@ -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)
}

View file

@ -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"`

View file

@ -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

View file

@ -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",

View file

@ -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