Skip to content

Commit

Permalink
Set LANG derived from user's locale on macOS (#351)
Browse files Browse the repository at this point in the history
* Set LANG derived from user's locale on macOS

* Preserve LANG if it is already set
  • Loading branch information
yoichi authored and sedwards2009 committed Jul 26, 2021
1 parent c4da397 commit e0cdc07
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions extensions/UnixSessionBackend/src/UnixSessionBackendExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class UnixBackend implements SessionBackend {

const ptyEnv = _.cloneDeep(process.env);
ptyEnv["TERM"] = "xterm-256color";
if (process.platform === "darwin" && !("LANG" in ptyEnv)) {
ptyEnv["LANG"] = this._readAppleLocale() + ".UTF-8";
}

let prop: string;
for (prop in sessionOptions.extraEnv) {
Expand Down Expand Up @@ -145,6 +148,20 @@ class UnixBackend implements SessionBackend {
});
}

private _readAppleLocale(): string {
try {
const result: string = <any> child_process.execFileSync("defaults",
["read", "-g", "AppleLocale"],
{encoding: "utf8"});
const locale = result.trim();
this._log.info("Found user locale: " + locale);
return locale;
} catch(e) {
this._log.warn("Couldn't run defaults command to find the user's locale. Defaulting to en_US");
return "en_US";
}
}

private _validateDirectoryPath(dirPath: string): string {
try {
const metadata = fs.statSync(dirPath);
Expand Down

0 comments on commit e0cdc07

Please sign in to comment.