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

Use Code Insiders #30

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
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.

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.
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")
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
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)
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)
}
Expand Down Expand Up @@ -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)
}
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()
func syncUserSettings(sshFlags string, host string, back bool, insiders bool) error {
localConfDir, err := configDir(insiders)
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()
func syncExtensions(sshFlags string, host string, back bool, insiders bool) error {
localExtensionsDir, err := extensionsDir(insiders)
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
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
}