diff --git a/.gitignore b/.gitignore index dc0daa9..52d5d04 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor bin .vscode sshcode +sshcode.exe \ No newline at end of file diff --git a/README.md b/README.md index a5db262..17e7047 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ We currently support: - Linux - MacOS - WSL +- Windows Git Bash (MINGW64) - Requires [rsynch for Windows](http://repo.msys2.org/msys/x86_64/rsync-3.1.3-1-x86_64.pkg.tar.xz) ## Usage diff --git a/main.go b/main.go index bc0de4a..de8ef25 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,9 @@ import ( "fmt" "math/rand" "os" + "os/user" + "path/filepath" + "runtime" "strings" "time" @@ -75,6 +78,12 @@ func (c *rootCmd) Run(fl *flag.FlagSet) { dir = "~" } + // Get linux relative path if on windows + if runtime.GOOS == "windows" { + dir = relativeWindowsPath(dir) + fmt.Printf("relative path is %s\n", dir) + } + err := sshCode(host, dir, options{ skipSync: c.skipSync, sshFlags: c.sshFlags, @@ -109,3 +118,24 @@ Arguments: helpTab, ) } + +func relativeWindowsPath(dir string) string { + fmt.Printf("Received '%s'\n", dir) + usr, err := user.Current() + if err != nil { + fmt.Printf("Could not get user: %v", err) + return dir + } + rel, err := filepath.Rel(usr.HomeDir, dir) + if err != nil { + return dir + } + rel = "~/" + filepath.ToSlash(rel) + return rel +} + +func gitbashWindowsDir(dir string) (res string) { + res = filepath.ToSlash(dir) + res = "/" + strings.Replace(res, ":", "", -1) + return res +} diff --git a/settings.go b/settings.go index ad962a3..a3bd1cd 100644 --- a/settings.go +++ b/settings.go @@ -24,6 +24,9 @@ func configDir() (string, error) { path = os.ExpandEnv("$HOME/.config/Code/User/") case "darwin": path = os.ExpandEnv("$HOME/Library/Application Support/Code/User/") + case "windows": + // Can't use the filepath.Clean function to keep Linux format path that works well with gitbash + return gitbashWindowsDir(os.ExpandEnv("$HOME/.config/Code/User")), nil default: return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS) } @@ -39,6 +42,9 @@ func extensionsDir() (string, error) { switch runtime.GOOS { case "linux", "darwin": path = os.ExpandEnv("$HOME/.vscode/extensions/") + case "windows": + // Can't use the filepath.Clean function to keep Linux format path that works well with gitbash + return gitbashWindowsDir(os.ExpandEnv("$HOME/.vscode/extensions")), nil default: return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS) } diff --git a/sshcode.go b/sshcode.go index 97e7502..65500eb 100644 --- a/sshcode.go +++ b/sshcode.go @@ -56,9 +56,10 @@ func sshCode(host, dir string, o options) error { dlScript := downloadScript(codeServerPath) // Downloads the latest code-server and allows it to be executed. - sshCmdStr := fmt.Sprintf("ssh %v %v '/usr/bin/env bash'", o.sshFlags, host) + // sshCmdStr := fmt.Sprintf("ssh %v %v /bin/bash -l", o.sshFlags, host) + sshCmdStr := fmt.Sprintf("ssh %v %v '/usr/bin/env bash -l'", o.sshFlags, host) - sshCmd := exec.Command("sh", "-c", sshCmdStr) + sshCmd := exec.Command("sh", "-l", "-c", sshCmdStr) sshCmd.Stdout = os.Stdout sshCmd.Stderr = os.Stderr sshCmd.Stdin = strings.NewReader(dlScript) @@ -353,8 +354,8 @@ wget -N https://codesrv-ci.cdr.sh/latest-linux ln latest-linux %v chmod +x %v`, codeServerPath, - filepath.Dir(codeServerPath), - filepath.Dir(codeServerPath), + filepath.ToSlash(filepath.Dir(codeServerPath)), + filepath.ToSlash(filepath.Dir(codeServerPath)), codeServerPath, codeServerPath, codeServerPath,