forked from coder/sshcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.go
56 lines (45 loc) · 1.2 KB
/
settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"os"
"path/filepath"
"runtime"
"golang.org/x/xerrors"
)
const (
vsCodeConfigDirEnv = "VSCODE_CONFIG_DIR"
vsCodeExtensionsDirEnv = "VSCODE_EXTENSIONS_DIR"
)
func configDir(insiders bool) (string, error) {
if env, ok := os.LookupEnv(vsCodeConfigDirEnv); ok {
return os.ExpandEnv(env), nil
}
var basePath string
switch runtime.GOOS {
case "linux":
basePath = os.ExpandEnv("$HOME/.config")
case "darwin":
basePath = os.ExpandEnv("$HOME/Library/Application Support")
default:
return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS)
}
if insiders {
return filepath.Join(basePath, "Code - Insiders", "User"), nil
}
return filepath.Join(basePath, "Code", "User"), nil
}
func extensionsDir(insiders bool) (string, error) {
if env, ok := os.LookupEnv(vsCodeExtensionsDirEnv); ok {
return os.ExpandEnv(env), nil
}
var basePath string
switch runtime.GOOS {
case "linux", "darwin":
basePath = os.ExpandEnv("$HOME")
default:
return "", xerrors.Errorf("unsupported platform: %s", runtime.GOOS)
}
if insiders {
return filepath.Join(basePath, ".vscode-insiders", "extensions"), nil
}
return filepath.Join(basePath, ".vscode", "extensions"), nil
}