diff --git a/pkg/remote/connutil.go b/pkg/remote/connutil.go index 263e3128..28d9174d 100644 --- a/pkg/remote/connutil.go +++ b/pkg/remote/connutil.go @@ -72,7 +72,7 @@ func GetWshVersion(client *ssh.Client) (string, error) { } func GetWshPath(client *ssh.Client) string { - defaultPath := filepath.Join("~", ".waveterm", "bin", "wsh") + defaultPath := "~/.waveterm/bin/wsh" session, err := client.NewSession() if err != nil { @@ -96,6 +96,18 @@ func GetWshPath(client *ssh.Client) string { return strings.TrimSpace(string(out)) } + // check cmd on windows since it requires an absolute path with backslashes + session, err = client.NewSession() + if err != nil { + log.Printf("unable to detect client's wsh path. using default. error: %v", err) + return defaultPath + } + + out, cmdErr := session.Output("(dir 2>&1 *``|echo %userprofile%\\.waveterm%\\.waveterm\\bin\\wsh.exe);&<# rem #>echo none") //todo + if cmdErr == nil && strings.TrimSpace(string(out)) != "none" { + return strings.TrimSpace(string(out)) + } + // no custom install, use default path return defaultPath } @@ -279,6 +291,9 @@ func CpHostToRemote(client *ssh.Client, sourcePath string, destPath string) erro func InstallClientRcFiles(client *ssh.Client) error { path := GetWshPath(client) + log.Printf("path to wsh searched is: %s", path) + log.Printf("in bytes is: %v", []byte(path)) + log.Printf("in bytes expected would be: %v", []byte("~/.waveterm/bin/wsh")) session, err := client.NewSession() if err != nil { diff --git a/pkg/util/shellutil/shellutil.go b/pkg/util/shellutil/shellutil.go index 858b8852..bf5a48f1 100644 --- a/pkg/util/shellutil/shellutil.go +++ b/pkg/util/shellutil/shellutil.go @@ -268,6 +268,9 @@ func initCustomShellStartupFilesInternal() error { return nil } wshDstPath := filepath.Join(binDir, "wsh") + if runtime.GOOS == "windows" { + wshDstPath = wshDstPath + ".exe" + } err = utilfn.AtomicRenameCopy(wshDstPath, wshFullPath, 0755) if err != nil { return fmt.Errorf("error copying wsh binary to bin: %v", err)