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

Commit

Permalink
Allow specifying alternate VS Code settings dirs
Browse files Browse the repository at this point in the history
Notably adds support for VS Codium and VS Code Insiders.

Resolves #34, #29
  • Loading branch information
ammario committed Apr 22, 2019
1 parent 7d359fc commit dcd29f0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 25 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ 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 alternate release of VS Code such as VS Code Insiders, you
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"

This comment has been minimized.

Copy link
@jeasonstudio

jeasonstudio Apr 23, 2019

on macos:

- export VSCODE_CONFIG_DIR="$HOME/.config/Code - Insiders/User"
+ export VSCODE_CONFIG_DIR="$HOME/Library/Application Support/Code - Insiders/User"

This comment has been minimized.

Copy link
@ammario

ammario Apr 23, 2019

Author Member

Fixing that here #50

export VSCODE_EXTENSIONS_DIR="$HOME/.vscode-insiders/extensions"
```

### Sync-back

By default, VS Code changes on the remote server won't be synced back
Expand Down
30 changes: 5 additions & 25 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os/exec"
"os/signal"
"path/filepath"
"runtime"
"strconv"
"strings"
"text/tabwriter"
Expand Down Expand Up @@ -66,6 +65,11 @@ func main() {
flag.Usage = func() {
fmt.Printf(`Usage: %v [FLAGS] HOST [DIR]
Start VS Code via 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
Arguments:
Expand Down Expand Up @@ -336,27 +340,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
}
46 changes: 46 additions & 0 deletions settings.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit dcd29f0

Please sign in to comment.