mirror of
https://github.com/coder/code-server.git
synced 2026-11-02 12:11:36 +08:00
Expand ~ in path options from the config file (#8055)
The shell expands ~ in command-line arguments, but values read from config.yaml were passed to path.resolve as-is, so `user-data-dir: ~/.config/code-server-data` resolved to `<cwd>/~/.config/code-server-data`.
This commit is contained in:
@@ -511,3 +511,18 @@ export function splitOnFirstEquals(str: string): [string, string | undefined] {
|
||||
const split = str.split(/=(.+)?/, 2)
|
||||
return [split[0], split[1]]
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand a leading `~` to the home directory. The shell does this for
|
||||
* command-line arguments but values from the config file are not expanded.
|
||||
* `~user` forms are left alone.
|
||||
*/
|
||||
export function expandTilde(p: string): string {
|
||||
if (p === "~") {
|
||||
return os.homedir()
|
||||
}
|
||||
if (p.startsWith("~/") || p.startsWith(`~${path.sep}`)) {
|
||||
return path.join(os.homedir(), p.slice(2))
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user