diff --git a/README.md b/README.md index 8ad9a86..59ba73e 100644 --- a/README.md +++ b/README.md @@ -51,8 +51,10 @@ on follow-up connections to the same server. To disable this feature entirely, pass the `--skipsync` flag. +You can specify `--insiders` to sync settings and extensions from VS Code Insiders. + ### 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. \ No newline at end of file +pass the `-b` flag. diff --git a/main.go b/main.go index fc46c1b..e32a4a1 100644 --- a/main.go +++ b/main.go @@ -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") + insiders = flag.Bool("insiders", false, "use configs and extensions from VSCode Insiders") ) flag.Usage = func() { - fmt.Printf(`Usage: [-skipsync] %v HOST [DIR] [SSH ARGS...] + fmt.Printf(`Usage: [-skipsync] [-insiders] %v HOST [DIR] [SSH ARGS...] Start code-server over SSH. More info: https://github.com/codercom/sshcode @@ -87,14 +88,14 @@ chmod +x ` + codeServerPath if !*skipSyncFlag { start := time.Now() flog.Info("syncing settings") - err = syncUserSettings(*sshFlags, host, false) + err = syncUserSettings(*sshFlags, host, false, *insiders) 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) + err = syncExtensions(*sshFlags, host, false, *insiders) if err != nil { flog.Fatal("failed to sync extensions: %v", err) } @@ -164,12 +165,12 @@ chmod +x ` + codeServerPath flog.Info("synchronizing VS Code back to local") - err = syncExtensions(*sshFlags, host, true) + err = syncExtensions(*sshFlags, host, true, *insiders) if err != nil { flog.Fatal("failed to sync extensions back: %v", err) } - err = syncUserSettings(*sshFlags, host, true) + err = syncUserSettings(*sshFlags, host, true, *insiders) if err != nil { flog.Fatal("failed to user settigns extensions back: %v", err) } @@ -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() +func syncUserSettings(sshFlags string, host string, back bool, insiders bool) error { + localConfDir, err := configDir(insiders) if err != nil { return err } @@ -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() +func syncExtensions(sshFlags string, host string, back bool, insiders bool) error { + localExtensionsDir, err := extensionsDir(insiders) if err != nil { return err } @@ -300,26 +301,36 @@ func rsync(src string, dest string, sshFlags string, excludePaths ...string) err return nil } -func configDir() (string, error) { - var path string +func configDir(insiders bool) (string, error) { + var basePath string switch runtime.GOOS { case "linux": - path = os.ExpandEnv("$HOME/.config/Code/User/") + basePath = os.ExpandEnv("$HOME/.config") case "darwin": - path = os.ExpandEnv("$HOME/Library/Application Support/Code/User/") + basePath = os.ExpandEnv("$HOME/Library/Application Support") default: return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS) } - return filepath.Clean(path), nil + + if insiders { + return filepath.Join(basePath, "Code - Insiders", "User"), nil + } + + return filepath.Join(basePath, "Code", "User"), nil } -func extensionsDir() (string, error) { - var path string +func extensionsDir(insiders bool) (string, error) { + var basePath string switch runtime.GOOS { case "linux", "darwin": - path = os.ExpandEnv("$HOME/.vscode/extensions/") + basePath = os.ExpandEnv("$HOME") default: return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS) } - return filepath.Clean(path), nil + + if insiders { + return filepath.Join(basePath,".vscode-insiders", "extensions"), nil + } + + return filepath.Join(basePath, ".vscode", "extensions"), nil }