diff --git a/cmd/xgo/shadow/exclude_path.go b/cmd/xgo/shadow/exclude_path.go new file mode 100755 index 00000000..7e431370 --- /dev/null +++ b/cmd/xgo/shadow/exclude_path.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" +) + +func excludeInList(dir string, path string, list []string) ([]string, error) { + n := len(list) + j := 0 + for i := 0; i < n; i++ { + d := list[i] + if d == dir { + continue + } + list[j] = d + j++ + } + if j == n { + return nil, fmt.Errorf("xgo shadow not found in PATH: %s", path) + } + return list[:j], nil +} diff --git a/cmd/xgo/shadow/prepare_unix.go b/cmd/xgo/shadow/prepare_unix.go index 3fe2aaa0..386b46b2 100644 --- a/cmd/xgo/shadow/prepare_unix.go +++ b/cmd/xgo/shadow/prepare_unix.go @@ -4,7 +4,6 @@ package main import ( - "fmt" "os" "path/filepath" "strings" @@ -12,22 +11,13 @@ import ( func exclude(dir string) (func(), error) { path := os.Getenv("PATH") - list := filepath.SplitList(path) - n := len(list) - j := 0 - for i := 0; i < n; i++ { - d := list[i] - if d == dir { - continue - } - list[j] = d - j++ - } - if j == n { - return nil, fmt.Errorf("xgo shadow not found in PATH: %s", dir) + + newList, err := excludeInList(dir, path, list) + if err != nil { + return nil, err } - os.Setenv("PATH", strings.Join(list[:j], string(filepath.ListSeparator))) + os.Setenv("PATH", strings.Join(newList, string(filepath.ListSeparator))) return func() { os.Setenv("PATH", path) }, nil diff --git a/cmd/xgo/shadow/prepare_windows.go b/cmd/xgo/shadow/prepare_windows.go index 3ec7b25c..79043a85 100644 --- a/cmd/xgo/shadow/prepare_windows.go +++ b/cmd/xgo/shadow/prepare_windows.go @@ -4,11 +4,24 @@ package main import ( - "fmt" + "os" + "path/filepath" + "strings" ) -var xgo_shadow int = "not support windows yet" +// test on powershell: +// $env:path="C:\Users\xhd2015\.xgo\shadow;"+$env:path func exclude(dir string) (func(), error) { - return nil, fmt.Errorf("windows not supported") + path := os.Getenv("path") + list := filepath.SplitList(path) + + newList, err := excludeInList(dir, path, list) + if err != nil { + return nil, err + } + os.Setenv("path", strings.Join(newList, string(filepath.ListSeparator))) + return func() { + os.Setenv("path", path) + }, nil } diff --git a/cmd/xgo/version.go b/cmd/xgo/version.go index 04945f79..8fca16f3 100644 --- a/cmd/xgo/version.go +++ b/cmd/xgo/version.go @@ -4,8 +4,8 @@ import "fmt" // auto updated const VERSION = "1.0.44" -const REVISION = "5a3329d7a88d9360bd34c434b2a4902fa302fdce+1" -const NUMBER = 288 +const REVISION = "53e47a022cd9314ede199ca6b70066352c6cec0f+1" +const NUMBER = 289 // manually updated const CORE_VERSION = "1.0.43"