From fa96dc1442c137f58e2584d17f959e80ee0f1f54 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Mon, 22 Apr 2019 14:12:24 -0500 Subject: [PATCH 1/4] Allow specifying alternative VS Code settings dirs Notably adds support for VS Codium and VS Code insiders. Resolves #34, #29 --- README.md | 12 ++++++++++++ main.go | 30 +++++------------------------- settings.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 25 deletions(-) create mode 100644 settings.go diff --git a/README.md b/README.md index 8ad9a86..8e1aa3f 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,18 @@ on follow-up connections to the same server. To disable this feature entirely, pass the `--skipsync` flag. +### Custom settings directories + +If you're using an alternative release of VS Code such as VS Code Insiders, you +will need to specify your configuration directory through the `VSCODE_CONFIG_DIR` +environment variable. + +The following will make `sshcode` work with VS Code insiders: + +```bash +export VSCODE_CONFIG_DIR="$HOME/.config/Code - Insiders/User" +``` + ### Sync-back By default, VS Code changes on the remote server won't be synced back diff --git a/main.go b/main.go index fdf4145..f14f55f 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,6 @@ import ( "os/exec" "os/signal" "path/filepath" - "runtime" "strconv" "strings" "time" @@ -36,6 +35,11 @@ func main() { fmt.Printf(`Usage: [-skipsync] %v HOST [DIR] [SSH ARGS...] Start code-server over SSH. + +Environment variables: + `+vsCodeConfigDirEnv+` use special VS Code settings dir. + `+vsCodeExtensionsDirEnv+` use special VS Code extensions dir. + More info: https://github.com/codercom/sshcode `, os.Args[0], ) @@ -301,27 +305,3 @@ 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 -} diff --git a/settings.go b/settings.go new file mode 100644 index 0000000..ad962a3 --- /dev/null +++ b/settings.go @@ -0,0 +1,46 @@ +package main + +import ( + "os" + "path/filepath" + "runtime" + + "golang.org/x/xerrors" +) + +const ( + vsCodeConfigDirEnv = "VSCODE_CONFIG_DIR" + vsCodeExtensionsDirEnv = "VSCODE_EXTENSIONS_DIR" +) + +func configDir() (string, error) { + if env, ok := os.LookupEnv(vsCodeConfigDirEnv); ok { + return os.ExpandEnv(env), nil + } + + 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) { + if env, ok := os.LookupEnv(vsCodeExtensionsDirEnv); ok { + return os.ExpandEnv(env), nil + } + + 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 +} From b4cabe219c8b82e38f76340e34c2fa8b10882b22 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Mon, 22 Apr 2019 14:17:19 -0500 Subject: [PATCH 2/4] fixup! Allow specifying alternative VS Code settings dirs --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8e1aa3f..ffe6034 100644 --- a/README.md +++ b/README.md @@ -54,10 +54,10 @@ To disable this feature entirely, pass the `--skipsync` flag. ### Custom settings directories If you're using an alternative release of VS Code such as VS Code Insiders, you -will need to specify your configuration directory through the `VSCODE_CONFIG_DIR` +must specify your configuration directory through the `VSCODE_CONFIG_DIR` environment variable. -The following will make `sshcode` work with VS Code insiders: +The following will make `sshcode` work with VS Code Insiders: ```bash export VSCODE_CONFIG_DIR="$HOME/.config/Code - Insiders/User" From 6b49bff676286354e1bb294663ea3cde061507d2 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Mon, 22 Apr 2019 14:27:02 -0500 Subject: [PATCH 3/4] fixup! Allow specifying alternative VS Code settings dirs --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ffe6034..155f59c 100644 --- a/README.md +++ b/README.md @@ -54,13 +54,14 @@ To disable this feature entirely, pass the `--skipsync` flag. ### Custom settings directories If you're using an alternative release of VS Code such as VS Code Insiders, you -must specify your configuration directory through the `VSCODE_CONFIG_DIR` -environment variable. +must specify your settings directories through the `VSCODE_CONFIG_DIR` and +`VSCODE_EXTENSIONS_DIR` environment variables. The following will make `sshcode` work with VS Code Insiders: ```bash export VSCODE_CONFIG_DIR="$HOME/.config/Code - Insiders/User" +export VSCODE_EXTENSIONS_DIR="$HOME/.vscode-insiders/extensions" ``` ### Sync-back From f246e9b9e774a84c661844dc6895e37f2a816eb4 Mon Sep 17 00:00:00 2001 From: Oren Cohen Date: Mon, 22 Apr 2019 22:33:00 +0300 Subject: [PATCH 4/4] Add Code Insiders option --- main.go | 19 ++++++++++--------- settings.go | 28 +++++++++++++++++++--------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index f14f55f..2b92421 100644 --- a/main.go +++ b/main.go @@ -29,10 +29,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. @@ -91,14 +92,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) } @@ -168,12 +169,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) } @@ -243,8 +244,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 } @@ -263,8 +264,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 } diff --git a/settings.go b/settings.go index ad962a3..ea1e902 100644 --- a/settings.go +++ b/settings.go @@ -13,34 +13,44 @@ const ( vsCodeExtensionsDirEnv = "VSCODE_EXTENSIONS_DIR" ) -func configDir() (string, error) { +func configDir(insiders bool) (string, error) { if env, ok := os.LookupEnv(vsCodeConfigDirEnv); ok { return os.ExpandEnv(env), nil } - var path string + 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) { +func extensionsDir(insiders bool) (string, error) { if env, ok := os.LookupEnv(vsCodeExtensionsDirEnv); ok { return os.ExpandEnv(env), nil } - var path string + 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 }