diff --git a/src/cli/notice.go b/src/cli/notice.go new file mode 100644 index 00000000..70a5bc9e --- /dev/null +++ b/src/cli/notice.go @@ -0,0 +1,34 @@ +package cli + +import ( + "fmt" + + "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/upgrade" + "github.com/spf13/cobra" +) + +// noticeCmd represents the get command +var noticeCmd = &cobra.Command{ + Use: "notice", + Short: "Print the upgrade notice when a new version is available.", + Long: "Print the upgrade notice when a new version is available.", + Args: cobra.NoArgs, + Run: func(cmd *cobra.Command, args []string) { + env := &platform.Shell{ + CmdFlags: &platform.Flags{ + Version: cliVersion, + }, + } + env.Init() + defer env.Close() + + if notice, hasNotice := upgrade.Notice(env); hasNotice { + fmt.Println(notice) + } + }, +} + +func init() { //nolint:gochecknoinits + RootCmd.AddCommand(noticeCmd) +} diff --git a/src/shell/init.go b/src/shell/init.go index 016cf32a..48fb4c30 100644 --- a/src/shell/init.go +++ b/src/shell/init.go @@ -210,7 +210,12 @@ func PrintInit(env platform.Environment) string { shell := env.Flags().Shell configFile := env.Flags().Config - var script string + + var ( + script, notice string + hasNotice bool + ) + switch shell { case PWSH, PWSH5: executable = quotePwshStr(executable) @@ -251,7 +256,13 @@ func PrintInit(env platform.Environment) string { default: return fmt.Sprintf("echo \"No initialization script available for %s\"", shell) } - notice, hasNotice := upgrade.Notice(env) + + // only run this for shells that support + // injecting the notice directly + if shell != PWSH && shell != PWSH5 { + notice, hasNotice = upgrade.Notice(env) + } + return strings.NewReplacer( "::OMP::", executable, "::CONFIG::", configFile, diff --git a/src/shell/scripts/omp.ps1 b/src/shell/scripts/omp.ps1 index 6a6df2b8..f4f38adf 100644 --- a/src/shell/scripts/omp.ps1 +++ b/src/shell/scripts/omp.ps1 @@ -30,11 +30,6 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock { $env:POSH_THEME = (Resolve-Path -Path ::CONFIG::).ProviderPath } - # print upgrade notice - if ("::UPGRADE::" -eq "true") { - Write-Host "::UPGRADENOTICE::" - } - # specific module support (disabled by default) if (($null -eq $env:POSH_GIT_ENABLED) -or ($null -eq (Get-Module 'posh-git'))) { $env:POSH_GIT_ENABLED = $false @@ -404,6 +399,11 @@ Example: } } + $notice = @(Start-Utf8Process $script:OMPExecutable @("notice")) + if ($notice) { + Write-Host $notice -NoNewline + } + Export-ModuleMember -Function @( "Set-PoshContext" "Enable-PoshTooltips"