From b2ddce6e103d389034fabe8dc7c2b260f32b0b9c Mon Sep 17 00:00:00 2001 From: Oren Cohen Date: Mon, 22 Apr 2019 16:16:00 +0300 Subject: [PATCH 1/4] Use Code Insiders config dir if exists --- main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.go b/main.go index fc46c1b..c17b717 100644 --- a/main.go +++ b/main.go @@ -302,24 +302,39 @@ func rsync(src string, dest string, sshFlags string, excludePaths ...string) err func configDir() (string, error) { var path string + var insiderPath string switch runtime.GOOS { case "linux": path = os.ExpandEnv("$HOME/.config/Code/User/") + insiderPath = os.ExpandEnv("$HOME/.config/Code - Insiders/User/") case "darwin": path = os.ExpandEnv("$HOME/Library/Application Support/Code/User/") + insiderPath = os.ExpandEnv("$HOME/Library/Application Support/Code - Insiders/User/") default: return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS) } + + if pathExists(insiderPath) { + return filepath.Clean(insiderPath), nil + } + return filepath.Clean(path), nil } func extensionsDir() (string, error) { var path string + var insiderPath string switch runtime.GOOS { case "linux", "darwin": path = os.ExpandEnv("$HOME/.vscode/extensions/") + insiderPath = os.ExpandEnv("$HOME/.vscode-insiders/extensions/") default: return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS) } + + if pathExists(insiderPath) { + return filepath.Clean(insiderPath), nil + } + return filepath.Clean(path), nil } From 221f918421ca29424969fada9630275c74d82de8 Mon Sep 17 00:00:00 2001 From: Oren Cohen Date: Mon, 22 Apr 2019 21:31:49 +0300 Subject: [PATCH 2/4] Add insiders flag --- main.go | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/main.go b/main.go index c17b717..cc5ca8a 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,7 @@ 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() { @@ -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,40 +301,41 @@ func rsync(src string, dest string, sshFlags string, excludePaths ...string) err return nil } -func configDir() (string, error) { +func configDir(insiders bool) (string, error) { var path string - var insiderPath string + var basePath string switch runtime.GOOS { case "linux": - path = os.ExpandEnv("$HOME/.config/Code/User/") - insiderPath = os.ExpandEnv("$HOME/.config/Code - Insiders/User/") + basePath = os.ExpandEnv("$HOME/.config") case "darwin": - path = os.ExpandEnv("$HOME/Library/Application Support/Code/User/") - insiderPath = os.ExpandEnv("$HOME/Library/Application Support/Code - Insiders/User/") + basePath = os.ExpandEnv("$HOME/Library/Application Support") default: return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS) } - if pathExists(insiderPath) { - return filepath.Clean(insiderPath), nil + if insiders { + path = fmt.Sprintf("%s/Code - Insiders/User/", basePath) + } else { + path = fmt.Sprintf("%s/Code/User/", basePath) } return filepath.Clean(path), nil } -func extensionsDir() (string, error) { +func extensionsDir(insiders bool) (string, error) { var path string - var insiderPath string + var basePath string switch runtime.GOOS { case "linux", "darwin": - path = os.ExpandEnv("$HOME/.vscode/extensions/") - insiderPath = os.ExpandEnv("$HOME/.vscode-insiders/extensions/") + basePath = os.ExpandEnv("$HOME") default: return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS) } - if pathExists(insiderPath) { - return filepath.Clean(insiderPath), nil + if insiders { + path = fmt.Sprintf("%s/.vscode-insiders/extensions/", basePath) + } else { + path = fmt.Sprintf("%s/.vscode/extensions/", basePath) } return filepath.Clean(path), nil From 619a4a0d5bd1febc0e4655597532107ffe5f21f9 Mon Sep 17 00:00:00 2001 From: Oren Cohen Date: Mon, 22 Apr 2019 22:11:43 +0300 Subject: [PATCH 3/4] Update readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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. From 0ee13fc671849bb2f600c7cd1a15f8651e8e6d2d Mon Sep 17 00:00:00 2001 From: Oren Cohen Date: Mon, 22 Apr 2019 22:12:44 +0300 Subject: [PATCH 4/4] Use filepath.Join instead of Sprintf --- main.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index cc5ca8a..e32a4a1 100644 --- a/main.go +++ b/main.go @@ -34,7 +34,7 @@ func main() { ) 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 @@ -302,7 +302,6 @@ func rsync(src string, dest string, sshFlags string, excludePaths ...string) err } func configDir(insiders bool) (string, error) { - var path string var basePath string switch runtime.GOOS { case "linux": @@ -314,16 +313,13 @@ func configDir(insiders bool) (string, error) { } if insiders { - path = fmt.Sprintf("%s/Code - Insiders/User/", basePath) - } else { - path = fmt.Sprintf("%s/Code/User/", basePath) + return filepath.Join(basePath, "Code - Insiders", "User"), nil } - return filepath.Clean(path), nil + return filepath.Join(basePath, "Code", "User"), nil } func extensionsDir(insiders bool) (string, error) { - var path string var basePath string switch runtime.GOOS { case "linux", "darwin": @@ -333,10 +329,8 @@ func extensionsDir(insiders bool) (string, error) { } if insiders { - path = fmt.Sprintf("%s/.vscode-insiders/extensions/", basePath) - } else { - path = fmt.Sprintf("%s/.vscode/extensions/", basePath) + return filepath.Join(basePath,".vscode-insiders", "extensions"), nil } - return filepath.Clean(path), nil + return filepath.Join(basePath, ".vscode", "extensions"), nil }