Skip to content
This repository has been 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
18 changes: 18 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"math/rand"
"os"
"path/filepath"
"runtime"
"strings"
"time"

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

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

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

//This section translates a windows path such as "C:\Users\user" to "\Users\user"
//AND removes the default paths for mingw and git4windows to fix specifying a file path breaking
func gitbashWindowsDir(dir string) (res string) {
res = filepath.ToSlash(dir)
res = strings.Replace(res, "C:", "", -1)

// If you dont use "C:\mingw64" as the location where you installed mingw, cop this and replace /mingw64 with your install path
res = strings.Replace(res, "/mingw64", "", -1)
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("/c/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("/c/Users/$USERNAME/.vscode/extensions/")), nil
default:
return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS)
}
Expand Down
27 changes: 20 additions & 7 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 @@ -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 = ".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 = ".local/share/code-server/extensions/"

var (
src = localExtensionsDir + "/"
Expand Down Expand Up @@ -483,7 +496,7 @@ func downloadScript(codeServerPath string) string {

[ "$(uname -m)" != "x86_64" ] && echo "Unsupported server architecture $(uname -m). code-server only has releases for x86_64 systems." && exit 1
pkill -f %v || true
mkdir -p ~/.local/share/code-server %v
mkdir -p $HOME/.local/share/code-server %v
cd %v
curlflags="-o latest-linux"
if [ -f latest-linux ]; then
Expand All @@ -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