This repository has been archived by the owner on Jan 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from codercom/env-settings
Add support for custom VS Code settings dirs
- Loading branch information
Showing
3 changed files
with
64 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |