From 87404454a4b9a801d28697e0258b19fee6868f57 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Fri, 11 Oct 2024 21:51:14 +0200 Subject: [PATCH] refactor(upgrade): allow setting from CLI --- src/cli/enable.go | 35 +-- src/config/config.go | 10 +- website/docs/installation/upgrade.mdx | 27 +- website/src/css/prism-rose-pine-moon.css | 328 +++++++++++------------ 4 files changed, 213 insertions(+), 187 deletions(-) diff --git a/src/cli/enable.go b/src/cli/enable.go index bf634883..42c34719 100644 --- a/src/cli/enable.go +++ b/src/cli/enable.go @@ -6,7 +6,6 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/cache" "github.com/jandedobbeleer/oh-my-posh/src/config" "github.com/jandedobbeleer/oh-my-posh/src/runtime" - "github.com/jandedobbeleer/oh-my-posh/src/upgrade" "github.com/spf13/cobra" ) @@ -19,8 +18,8 @@ This command is used to %s one of the following features: - notice` toggleArgs = []string{ - "notice", - "autoupgrade", + config.UPGRADENOTICE, + config.AUTOUPGRADE, } ) @@ -55,22 +54,24 @@ func toggleFeature(cmd *cobra.Command, feature string, enable bool) { env.Init() defer env.Close() + var key string + switch feature { case "notice": - if enable { - env.Cache().Delete(upgrade.CACHEKEY) - return - } - - env.Cache().Set(upgrade.CACHEKEY, "disabled", cache.INFINITE) + key = config.UPGRADENOTICE case "autoupgrade": - if enable { - env.Cache().Set(config.AUTOUPGRADE, "true", cache.INFINITE) - return - } - - env.Cache().Delete(config.AUTOUPGRADE) - default: - _ = cmd.Help() + key = config.AUTOUPGRADE } + + if len(key) == 0 { + _ = cmd.Help() + return + } + + if enable { + env.Cache().Set(key, "true", cache.INFINITE) + return + } + + env.Cache().Delete(key) } diff --git a/src/config/config.go b/src/config/config.go index edee9ea5..5facc537 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -14,7 +14,8 @@ const ( YAML string = "yaml" TOML string = "toml" - AUTOUPGRADE = "auto_upgrade" + AUTOUPGRADE = "autoupgrade" + UPGRADENOTICE = "upgradenotice" Version = 2 ) @@ -103,7 +104,12 @@ func (cfg *Config) Features() shell.Features { autoUpgrade = true } - if cfg.UpgradeNotice && !autoUpgrade { + upgradeNotice := cfg.UpgradeNotice + if _, OK := cfg.env.Cache().Get(UPGRADENOTICE); OK { + upgradeNotice = true + } + + if upgradeNotice && !autoUpgrade { feats = append(feats, shell.Notice) } diff --git a/website/docs/installation/upgrade.mdx b/website/docs/installation/upgrade.mdx index 4c7c0b4d..f4fdd60e 100644 --- a/website/docs/installation/upgrade.mdx +++ b/website/docs/installation/upgrade.mdx @@ -4,6 +4,9 @@ title: Upgrade sidebar_label: ♻️ Upgrade --- +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + ## Manual While you can always follow the upgrade steps listed under the installation section, @@ -13,11 +16,24 @@ you can also use the `upgrade` command to update Oh My Posh to the latest versio oh-my-posh upgrade ``` -## Automatic +## Automated -In case you want to enable auto-upgrades, you need to edit your configuration file. -If you don't yet have a configuration file, have a look at the [customize page][customize] to get started, -afterwards you can add the following line to your configuration file: + + + +```powershell +oh-my-posh enable autoupgrade +``` + + + import Config from "@site/src/components/Config.js"; @@ -27,4 +43,7 @@ import Config from "@site/src/components/Config.js"; }} /> + + + [customize]: /docs/installation/customize#custom-configuration diff --git a/website/src/css/prism-rose-pine-moon.css b/website/src/css/prism-rose-pine-moon.css index eb5eb16f..89153886 100644 --- a/website/src/css/prism-rose-pine-moon.css +++ b/website/src/css/prism-rose-pine-moon.css @@ -5,197 +5,197 @@ * Ported for PrismJS by fvrests [@fvrests] */ -code[class*="language-"], -pre[class*="language-"] { - color: #e0def4; - background: #232136; - font-family: "Cartograph CF", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", - monospace; - text-align: left; - white-space: pre; - word-spacing: normal; - word-break: normal; - word-wrap: normal; - line-height: 1.5; + code[class*="language-"], + pre[class*="language-"] { + color: #e0def4; + background: #232136; + font-family: "Cartograph CF", ui-monospace, SFMono-Regular, Menlo, Monaco, + Consolas, "Liberation Mono", "Courier New", monospace; + text-align: left; + white-space: pre; + word-spacing: normal; + word-break: normal; + word-wrap: normal; + line-height: 1.5; - -moz-tab-size: 4; - -o-tab-size: 4; - tab-size: 4; + -moz-tab-size: 4; + -o-tab-size: 4; + tab-size: 4; - -webkit-hyphens: none; - -moz-hyphens: none; - -ms-hyphens: none; - hyphens: none; + -webkit-hyphens: none; + -moz-hyphens: none; + -ms-hyphens: none; + hyphens: none; - @media print { - text-shadow: none; - } -} + @media print { + text-shadow: none; + } + } -/* Selection */ -code[class*="language-"]::-moz-selection, -pre[class*="language-"]::-moz-selection, -code[class*="language-"] ::-moz-selection, -pre[class*="language-"] ::-moz-selection { - background: #44415a; -} + /* Selection */ + code[class*="language-"]::-moz-selection, + pre[class*="language-"]::-moz-selection, + code[class*="language-"] ::-moz-selection, + pre[class*="language-"] ::-moz-selection { + background: #44415a; + } -code[class*="language-"]::selection, -pre[class*="language-"]::selection, -code[class*="language-"] ::selection, -pre[class*="language-"] ::selection { - background: #44415a; -} + code[class*="language-"]::selection, + pre[class*="language-"]::selection, + code[class*="language-"] ::selection, + pre[class*="language-"] ::selection { + background: #44415a; + } -/* Code (block & inline) */ -:not(pre) > code[class*="language-"], -pre[class*="language-"] { - color: #e0def4; - background: #232136; -} + /* Code (block & inline) */ + :not(pre) > code[class*="language-"], + pre[class*="language-"] { + color: #e0def4; + background: #232136; + } -/* Code blocks */ -pre[class*="language-"] { - padding: 1em; - margin: 0.5em 0; - overflow: auto; -} + /* Code blocks */ + pre[class*="language-"] { + padding: 1em; + margin: 0.5em 0; + overflow: auto; + } -/* Inline code */ -:not(pre) > code[class*="language-"] { - padding: 0.1em; - border-radius: 0.3em; - white-space: normal; - color: #e0def4; - background: #232136; -} + /* Inline code */ + :not(pre) > code[class*="language-"] { + padding: 0.1em; + border-radius: 0.3em; + white-space: normal; + color: #e0def4; + background: #232136; + } -/* Text style & opacity */ -.token.entity { - cursor: help; -} + /* Text style & opacity */ + .token.entity { + cursor: help; + } -.token.important, -.token.bold { - font-weight: bold; -} + .token.important, + .token.bold { + font-weight: bold; + } -.token.italic, -.token.selector, -.token.doctype, -.token.attr-name, -.token.inserted, -.token.deleted, -.token.comment, -.token.prolog, -.token.cdata, -.token.constant, -.token.parameter, -.token.url { - font-style: italic; -} + .token.italic, + .token.selector, + .token.doctype, + .token.attr-name, + .token.inserted, + .token.deleted, + .token.comment, + .token.prolog, + .token.cdata, + .token.constant, + .token.parameter, + .token.url { + font-style: italic; + } -.token.url { - text-decoration: underline; -} + .token.url { + text-decoration: underline; + } -.namespace { - opacity: 0.7; -} + .namespace { + opacity: 0.7; + } -/* Syntax highlighting */ -.token.constant { - color: #e0def4; -} + /* Syntax highlighting */ + .token.constant { + color: #e0def4; + } -.token.comment, -.token.prolog, -.token.cdata, -.token.punctuation { - color: #908caa; -} + .token.comment, + .token.prolog, + .token.cdata, + .token.punctuation { + color: #908caa; + } -.token.delimiter, -.token.important, -.token.atrule, -.token.operator, -.token.keyword { - color: #3e8fb0; -} + .token.delimiter, + .token.important, + .token.atrule, + .token.operator, + .token.keyword { + color: #3e8fb0; + } -.token.tag, -.token.tag .punctuation, -.token.doctype, -.token.variable, -.token.regex, -.token.class-name, -.token.selector, -.token.inserted { - color: #9ccfd8; -} + .token.tag, + .token.tag .punctuation, + .token.doctype, + .token.variable, + .token.regex, + .token.class-name, + .token.selector, + .token.inserted { + color: #9ccfd8; + } -.token.boolean, -.token.entity, -.token.number, -.token.symbol, -.token.function { - color: #ea9a97; -} + .token.boolean, + .token.entity, + .token.number, + .token.symbol, + .token.function { + color: #ea9a97; + } -.token.string, -.token.char, -.token.property, -.token.attr-value, -.token.attr-value .punctuation { - color: #f6c177; -} + .token.string, + .token.char, + .token.property, + .token.attr-value, + .token.attr-value .punctuation { + color: #f6c177; + } -.token.parameter, -.token.url, -.token.name, -.token.attr-name, -.token.builtin { - color: #c4a7e7; -} + .token.parameter, + .token.url, + .token.name, + .token.attr-name, + .token.builtin { + color: #c4a7e7; + } -.token.deleted { - color: #eb6f92; -} + .token.deleted { + color: #eb6f92; + } -/* Insertions & deletions */ -.token.inserted { - background: rgba(156 207 216 0.12); -} + /* Insertions & deletions */ + .token.inserted { + background: rgba(156 207 216 0.12); + } -.token.deleted { - background: rgba(235 111 146 0.12); -} + .token.deleted { + background: rgba(235 111 146 0.12); + } -/* Line highlighting */ -pre[data-line] { - position: relative; -} + /* Line highlighting */ + pre[data-line] { + position: relative; + } -pre[class*="language-"] > code[class*="language-"] { - position: relative; - z-index: 1; -} + pre[class*="language-"] > code[class*="language-"] { + position: relative; + z-index: 1; + } -.line-highlight, -.highlight-lines .highlighted { - position: absolute; - left: 0; - right: 0; - padding: inherit 0; - margin-top: 1em; + .line-highlight, + .highlight-lines .highlighted { + position: absolute; + left: 0; + right: 0; + padding: inherit 0; + margin-top: 1em; - background: #44415a; - box-shadow: inset 5px 0 0 #e0def4; + background: #44415a; + box-shadow: inset 5px 0 0 #e0def4; - z-index: 0; + z-index: 0; - pointer-events: none; + pointer-events: none; - line-height: inherit; - white-space: pre; -} + line-height: inherit; + white-space: pre; + }