◐ Shell
reader mode source ↗
Skip to content
This repository was archived by the owner on Jan 17, 2021. It is now read-only.
Closed
Show file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ on follow-up connections to the same server.

To disable this feature entirely, pass the `--skipsync` flag.

### Sync-back

By default, VS Code changes on the remote server won't be synced back
when the connection closes. To synchronize back to local when the connection ends,
pass the `-b` flag.
47 changes: 29 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ func main() {
skipSyncFlag = flag.Bool("skipsync", false, "skip syncing local settings and extensions to remote host")
sshFlags = flag.String("ssh-flags", "", "custom SSH flags")
syncBack = flag.Bool("b", false, "sync extensions back on termination")
)

flag.Usage = func() {
fmt.Printf(`Usage: [-skipsync] %v HOST [DIR] [SSH ARGS...]

Start code-server over SSH.
More info: https://github.com/codercom/sshcode
Expand Down Expand Up @@ -87,14 +88,14 @@ chmod +x ` + codeServerPath
if !*skipSyncFlag {
start := time.Now()
flog.Info("syncing settings")
err = syncUserSettings(*sshFlags, host, false)
if err != nil {
flog.Fatal("failed to sync settings: %v", err)
}
flog.Info("synced settings in %s", time.Since(start))

flog.Info("syncing extensions")
err = syncExtensions(*sshFlags, host, false)
if err != nil {
flog.Fatal("failed to sync extensions: %v", err)
}
Expand Down @@ -164,12 +165,12 @@ chmod +x ` + codeServerPath

flog.Info("synchronizing VS Code back to local")

err = syncExtensions(*sshFlags, host, true)
if err != nil {
flog.Fatal("failed to sync extensions back: %v", err)
}

err = syncUserSettings(*sshFlags, host, true)
if err != nil {
flog.Fatal("failed to user settigns extensions back: %v", err)
}
Expand Down Expand Up @@ -237,8 +238,8 @@ func randomPort() (string, error) {
return "", xerrors.Errorf("max number of tries exceeded: %d", maxTries)
}

func syncUserSettings(sshFlags string, host string, back bool) error {
localConfDir, err := configDir()
if err != nil {
return err
}
Expand All @@ -257,8 +258,8 @@ func syncUserSettings(sshFlags string, host string, back bool) error {
return rsync(src, dest, sshFlags, "workspaceStorage", "logs", "CachedData")
}

func syncExtensions(sshFlags string, host string, back bool) error {
localExtensionsDir, err := extensionsDir()
if err != nil {
return err
}
Expand Down Expand Up @@ -300,26 +301,36 @@ func rsync(src string, dest string, sshFlags string, excludePaths ...string) err
return nil
}

func configDir() (string, error) {
var path string
switch runtime.GOOS {
case "linux":
path = os.ExpandEnv("$HOME/.config/Code/User/")
case "darwin":
path = os.ExpandEnv("$HOME/Library/Application Support/Code/User/")
default:
return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS)
}
return filepath.Clean(path), nil
}

func extensionsDir() (string, error) {
var path string
switch runtime.GOOS {
case "linux", "darwin":
path = os.ExpandEnv("$HOME/.vscode/extensions/")
default:
return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS)
}
return filepath.Clean(path), nil
}
Toggle all file notes Toggle all file annotations