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

Windows #118

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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 @@ -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,
Expand Down Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
9 changes: 5 additions & 4 deletions sshcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The login shell stuff should be in a separate PR as it's unrelated to Git Bash for Windows support.


sshCmd := exec.Command("sh", "-c", sshCmdStr)
sshCmd := exec.Command("sh", "-l", "-c", sshCmdStr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SSH is called from more places than just this, so if we're going to change sh to a login shell so it reads the profile we should also do this every else.

sshCmd.Stdout = os.Stdout
sshCmd.Stderr = os.Stderr
sshCmd.Stdin = strings.NewReader(dlScript)
Expand Down Expand Up @@ -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,
Expand Down