From b22e57576f0e3f316a784aec92530da3461e0720 Mon Sep 17 00:00:00 2001 From: lihan Date: Thu, 21 Dec 2023 09:55:09 +0800 Subject: [PATCH] feat: in unix-like systems, replace the old shell process with a new one. --- .github/workflows/go-releaser.yml | 2 +- .goreleaser.yaml | 2 ++ README.md | 13 +++++++------ env/common_env.go | 2 +- env/macos_env.go | 18 ++++++------------ env/windows_env.go | 2 +- sdk/sdk.go | 4 +++- 7 files changed, 21 insertions(+), 22 deletions(-) diff --git a/.github/workflows/go-releaser.yml b/.github/workflows/go-releaser.yml index ffa89da4..0e2d4699 100644 --- a/.github/workflows/go-releaser.yml +++ b/.github/workflows/go-releaser.yml @@ -38,6 +38,6 @@ jobs: env: FURY_TOKEN: ${{ secrets.FURY_TOKEN }} run: | - for filename in dist/vfox*.rpm; do + for filename in dist/vfox*.{rpm,deb,apk}; do curl -F package=@"$filename" https://{$FURY_TOKEN}@push.fury.io/versionfox/ done \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 565cd0b5..1172f299 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -139,6 +139,8 @@ nfpms: mode: 0644 formats: - rpm + - apk + - deb rpm: group: Development/Tools diff --git a/README.md b/README.md index 41752959..c608626f 100644 --- a/README.md +++ b/README.md @@ -72,13 +72,14 @@ $ curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | ### Windows -On Windows, you need to run the PowerShell script install.ps1 as an administrator. Right-click the Start menu, choose " -Windows PowerShell (Administrator)" to open a PowerShell window with administrative privileges. Then, enter the -following command in the PowerShell window: +For Windows users, please follow the steps below to install: -```powershell -Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/version-fox/vfox/main/install.ps1')) -``` +1. Navigate to the [Releases](https://github.com/version-fox/vfox/releases) page of this repository. +2. Download the latest `setup.exe` file. +3. Once the download is complete, double-click the `setup.exe` file to start the installation process. +4. Follow the prompts in the installation wizard to complete the installation. + +Please ensure that you have the necessary permissions to install software on your machine. ## Usage diff --git a/env/common_env.go b/env/common_env.go index 6f486895..b290e26b 100644 --- a/env/common_env.go +++ b/env/common_env.go @@ -23,7 +23,7 @@ type Manager interface { Load([]*KV) error Get(key string) (string, error) Remove(key string) error - ReShell() error + ReShell(callback func()) error } type KV struct { diff --git a/env/macos_env.go b/env/macos_env.go index 950a213f..3c11ce36 100644 --- a/env/macos_env.go +++ b/env/macos_env.go @@ -23,10 +23,10 @@ import ( "fmt" "github.com/version-fox/vfox/util" "os" - "os/exec" "os/user" "path/filepath" "strings" + "syscall" ) const ( @@ -45,17 +45,11 @@ type macosEnvManager struct { pathMap map[string]string } -func (m *macosEnvManager) ReShell() error { - // flush env to file - m.Flush() - command := exec.Command(m.shellInfo.ShellPath) - command.Stdin = os.Stdin - command.Stdout = os.Stdout - command.Stderr = os.Stderr - if err := command.Start(); err != nil { - return err - } - if err := command.Wait(); err != nil { +func (m *macosEnvManager) ReShell(callback func()) error { + callback() + err := syscall.Exec(m.shellInfo.ShellPath, []string{m.shellInfo.ShellPath}, syscall.Environ()) + if err != nil { + fmt.Printf("Failed to exec shell, err:%s\n", err.Error()) return err } return nil diff --git a/env/windows_env.go b/env/windows_env.go index 9a8fe3e9..6677cb38 100644 --- a/env/windows_env.go +++ b/env/windows_env.go @@ -142,7 +142,7 @@ func (w *windowsEnvManager) Remove(key string) error { return nil } -func (w *windowsEnvManager) ReShell() error { +func (w *windowsEnvManager) ReShell(callback func()) error { // flush env to file w.Flush() command := exec.Command(w.shellInfo.ShellPath) diff --git a/sdk/sdk.go b/sdk/sdk.go index cf4ecade..3364e508 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -194,7 +194,9 @@ func (b *Sdk) Use(version Version) error { outputLabel = label } pterm.Printf("Now using %s.\n", pterm.LightGreen(outputLabel)) - return b.sdkManager.EnvManager.ReShell() + return b.sdkManager.EnvManager.ReShell(func() { + b.sdkManager.Close() + }) } func (b *Sdk) List() []Version {