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

GitBash and MinGW support #132

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8ef3fdd
clean push
Merith-TK Aug 15, 2019
1e63329
patched
Merith-TK Aug 15, 2019
8346a94
fixed stupid error
Merith-TK Aug 15, 2019
1066cd9
requested changes 8-14-2019
Merith-TK Aug 16, 2019
075ec62
Merge branch 'master' into msys-support
Merith-TK Aug 24, 2019
e0b9466
Merge branch 'master' into msys-support
Merith-TK Aug 27, 2019
431fa0a
Merge branch 'master' into msys-support
Merith-TK Sep 17, 2019
6356414
rewrite path conversion for msys (UNTESTED)
Merith-TK Sep 17, 2019
c0a2e2e
rewrite path conversion for msys (WORKING)
Merith-TK Sep 18, 2019
2466c65
Merge branch 'master' into msys-support
Merith-TK Oct 2, 2019
b0b134a
fix ghost path creation
Merith-TK Oct 2, 2019
059db65
Merge branch 'msys-support' of https://github.com/Merith-TK/sshcode i…
Merith-TK Oct 2, 2019
3675d80
Fix opening remote path (UNTESTED)
Merith-TK Oct 2, 2019
06c95c2
Merge branch 'master' into msys-support
Merith-TK Oct 31, 2019
2a12990
Fix windows sending literal string / pass travis
Merith-TK Nov 3, 2019
fb39251
Merged Eargollo PR Manually
Merith-TK Nov 11, 2019
8bff186
prevent lint.sh and ensuremod.sh from failing in travis
Merith-TK Nov 11, 2019
b895d1b
Fixed Chrome, renamed 'msysPath' to 'winPath'
Merith-TK Nov 12, 2019
73309c7
fix msys-support completely, fully functional
Merith-TK Nov 30, 2019
0ce0913
Merge branch 'master' into msys-support
Merith-TK Dec 9, 2019
b8b9ab8
remove winVarFix()
Merith-TK Feb 1, 2020
67cb96d
Simplify/rewrite directory detection.
Merith-TK Apr 8, 2020
e9c47f2
Revert ms-edge modifications
Merith-TK Apr 8, 2020
836d024
fix broken revert
Merith-TK Apr 8, 2020
c2b11f4
add pr suggestions
Merith-TK Apr 8, 2020
ad0b772
add pr suggestions
Merith-TK Apr 9, 2020
8084597
fix typo
Merith-TK Apr 18, 2020
5fa66f3
fix typo
Merith-TK Apr 19, 2020
8e9ee5f
Remove unnecessary log
deansheather Apr 20, 2020
d3536be
Remove unnecessary HasPrefix check
deansheather Apr 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 19 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,15 @@ 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, copy this and replace /mingw64 with your install path
res = strings.Replace(res, "/mingw64", "", -1)
res = strings.Replace(res, "/msys", "", -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