Skip to content

Commit 5bb6e05

Browse files
committed
utils: new helper function for getting platform
this is needed for settings paths that contain the platform, such as terminal settings
1 parent ac7e403 commit 5bb6e05

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/utils.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from 'vscode';
22
import * as temp from 'temp';
33
import * as fs from 'fs';
4+
import * as os from 'os';
45
import { isArray } from 'util';
56

67
const toastDuration = 5000;
@@ -74,3 +75,22 @@ export function toastStatusBarMessage(message: string): void {
7475
export function setContext(context: string, state: boolean): void {
7576
vscode.commands.executeCommand('setContext', context, state);
7677
}
78+
79+
/**
80+
* Gets the runtime platform suitable for use in settings lookup.
81+
*/
82+
export function getPlatform(): 'windows' | 'osx' | 'linux' | undefined {
83+
let platform: 'windows' | 'osx' | 'linux' | undefined;
84+
switch (os.platform()) {
85+
case 'win32':
86+
platform = 'windows';
87+
break;
88+
case 'darwin':
89+
platform = 'osx';
90+
break;
91+
case 'linux':
92+
platform = 'linux';
93+
break;
94+
}
95+
return platform;
96+
}

0 commit comments

Comments
 (0)