Skip to content

Commit

Permalink
feat: in unix-like systems, replace the old shell process with a new …
Browse files Browse the repository at this point in the history
…one.
  • Loading branch information
aooohan committed Dec 21, 2023
1 parent 8ffc91a commit b22e575
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ nfpms:
mode: 0644
formats:
- rpm
- apk
- deb
rpm:
group: Development/Tools
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion env/common_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 6 additions & 12 deletions env/macos_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"fmt"
"github.com/version-fox/vfox/util"
"os"
"os/exec"
"os/user"
"path/filepath"
"strings"
"syscall"
)

const (
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion env/windows_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b22e575

Please sign in to comment.