Skip to content
This repository was archived by the owner on Jan 17, 2021. It is now read-only.

MSYS/MINGW Client Support (FINNALLY Working) #127

Closed
wants to merge 13 commits into from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor
bin
.vscode
sshcode
sshcode.exe
30 changes: 30 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"fmt"
"math/rand"
"os"
"os/user"
"path/filepath"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -77,6 +80,11 @@ func (c *rootCmd) Run(fl *flag.FlagSet) {
dir = "~"
}

// Get linux relative path if on windows
if runtime.GOOS == "windows" {
dir = relativeWindowsPath(dir)
}

err := sshCode(host, dir, options{
skipSync: c.skipSync,
sshFlags: c.sshFlags,
Expand Down Expand Up @@ -112,3 +120,25 @@ Arguments:
helpTab,
)
}

func relativeWindowsPath(dir string) string {
usr, err := user.Current()
if err != nil {
flog.Error("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
}

// gitbashWindowsDir translates a directory similar to `C:\Users\username\path` to `~/path` for compatibility with Git bash.
func gitbashWindowsDir(dir string) (res string) {
res = filepath.ToSlash(dir)
res = strings.Replace(res, "C:", "", -1)
//res2 =
return res
}
4 changes: 4 additions & 0 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func configDir() (string, error) {
path = os.ExpandEnv("$HOME/.config/Code/User/")
case "darwin":
path = os.ExpandEnv("$HOME/Library/Application Support/Code/User/")
case "windows":
return gitbashWindowsDir(os.ExpandEnv("/Users/$USERNAME/AppData/Roaming/Code/User")), nil
default:
return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS)
}
Expand All @@ -39,6 +41,8 @@ func extensionsDir() (string, error) {
switch runtime.GOOS {
case "linux", "darwin":
path = os.ExpandEnv("$HOME/.vscode/extensions/")
case "windows":
return gitbashWindowsDir(os.ExpandEnv("/Users/$USERNAME/.vscode/extensions/")), nil
default:
return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS)
}
Expand Down
29 changes: 21 additions & 8 deletions sshcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os/exec"
"os/signal"
"path/filepath"
"runtime"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -199,9 +200,9 @@ func expandPath(path string) string {
// string with the homedir as having a tilde in the middle of a filename is valid.
homedir := os.Getenv("HOME")
if homedir != "" {
if path == "~" {
if path == "$HOME" {
path = homedir
} else if strings.HasPrefix(path, "~/") {
} else if strings.HasPrefix(path, "$HOME/") {
path = filepath.Join(homedir, path[2:])
}
}
Expand Down Expand Up @@ -237,11 +238,14 @@ func openBrowser(url string) {
var openCmd *exec.Cmd

const (
macPath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
wslPath = "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"
macPath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
wslPath = "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"
msysPath = "/Program Files (x86)/Google/Chrome/Application/chrome.exe"
)

switch {
case commandExists("chrome"):
openCmd = exec.Command("chrome", chromeOptions(url)...)
case commandExists("google-chrome"):
openCmd = exec.Command("google-chrome", chromeOptions(url)...)
case commandExists("google-chrome-stable"):
Expand All @@ -254,6 +258,8 @@ func openBrowser(url string) {
openCmd = exec.Command(macPath, chromeOptions(url)...)
case pathExists(wslPath):
openCmd = exec.Command(wslPath, chromeOptions(url)...)
case pathExists(msysPath):
openCmd = exec.Command(msysPath, chromeOptions(url)...)
default:
err := browser.OpenURL(url)
if err != nil {
Expand Down Expand Up @@ -308,6 +314,13 @@ func randomPort() (string, error) {
// checkSSHDirectory performs sanity and safety checks on sshDirectory, and
// returns a new value for o.reuseConnection depending on the checks.
func checkSSHDirectory(sshDirectory string, reuseConnection bool) bool {

if runtime.GOOS == "windows" {
flog.Info("OS is windows, disabling connection reuse feature")
//reuseConnection = false
return false
}

sshDirectoryMode, err := os.Lstat(expandPath(sshDirectory))
if err != nil {
if reuseConnection {
Expand Down Expand Up @@ -410,7 +423,7 @@ func syncUserSettings(sshFlags string, host string, back bool) error {
return err
}

const remoteSettingsDir = "~/.local/share/code-server/User/"
const remoteSettingsDir = "$HOME/.local/share/code-server/User/"

var (
src = localConfDir + "/"
Expand All @@ -436,7 +449,7 @@ func syncExtensions(sshFlags string, host string, back bool) error {
return err
}

const remoteExtensionsDir = "~/.local/share/code-server/extensions/"
const remoteExtensionsDir = "$HOME/.local/share/code-server/extensions/"

var (
src = localExtensionsDir + "/"
Expand Down Expand Up @@ -494,8 +507,8 @@ curl $curlflags 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,
Expand Down