Skip to content

Commit

Permalink
fix(upgrade): enable for all platforms
Browse files Browse the repository at this point in the history
resolves #5184
  • Loading branch information
JanDeDobbeleer committed Jun 29, 2024
1 parent dc002fc commit 3537f3f
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 138 deletions.
1 change: 0 additions & 1 deletion src/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func runInit(shellName string) {
shell.Tooltips = len(cfg.Tooltips) > 0
shell.ShellIntegration = cfg.ShellIntegration
shell.PromptMark = shellName == shell.FISH && cfg.ITermFeatures != nil && cfg.ITermFeatures.Contains(ansi.PromptMark)
shell.AutoUpgrade = cfg.AutoUpgrade && upgrade.Supported

for i, block := range cfg.Blocks {
// only fetch cursor position when relevant
Expand Down
9 changes: 8 additions & 1 deletion src/cli/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"fmt"
"runtime"
"slices"

"github.com/jandedobbeleer/oh-my-posh/src/engine"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
Expand All @@ -19,7 +20,13 @@ var upgradeCmd = &cobra.Command{
Long: "Upgrade when a new version is available.",
Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) {
if runtime.GOOS == platform.LINUX {
supportedPlatforms := []string{
platform.WINDOWS,
platform.DARWIN,
platform.LINUX,
}

if !slices.Contains(supportedPlatforms, runtime.GOOS) {
fmt.Print("\n⚠️ upgrade is not supported on this platform\n\n")
return
}
Expand Down
3 changes: 2 additions & 1 deletion src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/alecthomas/repr v0.4.0 // indirect
github.com/esimov/stackblur-go v1.1.0
github.com/fogleman/gg v1.3.0
github.com/google/uuid v1.6.0
github.com/google/uuid v1.6.0 // indirect
github.com/gookit/color v1.5.4
github.com/huandu/xstrings v1.5.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand All @@ -35,6 +35,7 @@ require (
github.com/goccy/go-yaml v1.11.3
github.com/gookit/goutil v0.6.15
github.com/hashicorp/hcl/v2 v2.21.0
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf
github.com/mattn/go-runewidth v0.0.15
github.com/pelletier/go-toml/v2 v2.2.2
github.com/spf13/cobra v1.8.1
Expand Down
2 changes: 2 additions & 0 deletions src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf h1:WfD7VjIE6z8dIvMsI4/s+1qr5EL+zoIGev1BQj1eoJ8=
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf/go.mod h1:hyb9oH7vZsitZCiBt0ZvifOrB+qc8PS5IiilCIb87rg=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jandedobbeleer/clipboard v0.1.4-1 h1:rJehm5W0a3hvjcxyB3snqLBV4yvMBBc12JyMP7ngNQw=
Expand Down
14 changes: 1 addition & 13 deletions src/upgrade/cli.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build windows || darwin

package upgrade

import (
Expand All @@ -23,16 +21,6 @@ var (
title string
)

const (
upgradeNotice = `
A new release of Oh My Posh is available: %s → %s
To upgrade, run: 'oh-my-posh upgrade'
To enable automated upgrades, set 'auto_upgrade' to 'true' in your configuration.
`
Supported = true
)

type resultMsg string

type state int
Expand Down Expand Up @@ -71,7 +59,7 @@ func (m *model) Init() tea.Cmd {
return
}

program.Send(resultMsg(successMsg))
program.Send(resultMsg("🚀 Upgrade successful, restart your shell to take full advantage of the new functionality."))
}()
}()

Expand Down
46 changes: 0 additions & 46 deletions src/upgrade/cli_darwin.go

This file was deleted.

19 changes: 0 additions & 19 deletions src/upgrade/cli_other.go

This file was deleted.

56 changes: 0 additions & 56 deletions src/upgrade/cli_windows.go

This file was deleted.

39 changes: 39 additions & 0 deletions src/upgrade/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package upgrade

import (
"fmt"
"os"
"runtime"

"github.com/inconshreveable/go-update"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
)

func install() error {
setState(validating)

executable, err := os.Executable()
if err != nil {
return err
}

extension := ""
if runtime.GOOS == platform.WINDOWS {
extension = ".exe"
}

asset := fmt.Sprintf("posh-%s-%s%s", runtime.GOOS, runtime.GOARCH, extension)

setState(downloading)

data, err := downloadAsset(asset)
if err != nil {
return err
}

defer data.Close()

return update.Apply(data, update.Options{
TargetPath: executable,
})
}
7 changes: 7 additions & 0 deletions src/upgrade/notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ type release struct {
const (
RELEASEURL = "https://api.github.com/repos/jandedobbeleer/oh-my-posh/releases/latest"
CACHEKEY = "upgrade_check"

upgradeNotice = `
A new release of Oh My Posh is available: %s → %s
To upgrade, run: 'oh-my-posh upgrade'
To enable automated upgrades, set 'auto_upgrade' to 'true' in your configuration.
`
)

func Latest(env platform.Environment) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/configuration/general.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ For example, the following is a valid `--config` flag:
| `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` | disables the notice that a new upgrade is available when `auto_upgrade` is disabled, and the notice that no new upgrade is available when `auto_upgrade` is enabled |
| `auto_upgrade` | `boolean` | enable automatic upgrades for Oh My Posh (supports Windows/macOS only) |
| `auto_upgrade` | `boolean` | enable automatic upgrades for Oh My Posh (supports Windows, macOS and Linux) |
| `iterm_features` | `[]string` | enable iTerm2 specific features:<ul><li>`prompt_mark`: add the `iterm2_prompt_mark` [function][iterm2-si] for supported shells</li><li>`current_dir`: expose the current directory for iTerm2</li><li>`remote_host`: expose the current remote and user for iTerm2</li></ul> |

### JSON Schema Validation
Expand Down

0 comments on commit 3537f3f

Please sign in to comment.