fix(pwsh): print upgrade notice in UTF8

resolves #3606
This commit is contained in:
Jan De Dobbeleer 2023-03-21 12:44:13 +01:00 committed by Jan De Dobbeleer
parent 3b1823682d
commit c901575413
3 changed files with 52 additions and 7 deletions

34
src/cli/notice.go Normal file
View file

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

View file

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

View file

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