This commit is contained in:
69
src/utils/osUtils.ts
Normal file
69
src/utils/osUtils.ts
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import * as os from 'os';
|
||||||
|
import * as path from 'path';
|
||||||
|
import { TerminalType } from '../models/types';
|
||||||
|
|
||||||
|
export class OSUtils {
|
||||||
|
getPlatform(): NodeJS.Platform {
|
||||||
|
return process.platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
isMacOS(): boolean {
|
||||||
|
return process.platform === 'darwin';
|
||||||
|
}
|
||||||
|
|
||||||
|
isLinux(): boolean {
|
||||||
|
return process.platform === 'linux';
|
||||||
|
}
|
||||||
|
|
||||||
|
isWindows(): boolean {
|
||||||
|
return process.platform === 'win32';
|
||||||
|
}
|
||||||
|
|
||||||
|
getHomeDir(): string {
|
||||||
|
return os.homedir();
|
||||||
|
}
|
||||||
|
|
||||||
|
getTmpDir(): string {
|
||||||
|
return os.tmpdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
detectTerminalType(): TerminalType {
|
||||||
|
if (this.isMacOS()) {
|
||||||
|
return 'iterm2';
|
||||||
|
}
|
||||||
|
return 'tmux';
|
||||||
|
}
|
||||||
|
|
||||||
|
getDefaultShell(): string {
|
||||||
|
return process.env.SHELL || '/bin/bash';
|
||||||
|
}
|
||||||
|
|
||||||
|
expandPath(filePath: string): string {
|
||||||
|
if (filePath.startsWith('~')) {
|
||||||
|
return path.join(this.getHomeDir(), filePath.slice(1));
|
||||||
|
}
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
getTmuxPath(): string {
|
||||||
|
return this.isMacOS() ? '/usr/local/bin/tmux' : '/usr/bin/tmux';
|
||||||
|
}
|
||||||
|
|
||||||
|
getScreenPath(): string {
|
||||||
|
return this.isMacOS() ? '/usr/local/bin/screen' : '/usr/bin/screen';
|
||||||
|
}
|
||||||
|
|
||||||
|
async getCurrentCwd(): Promise<string> {
|
||||||
|
return process.cwd();
|
||||||
|
}
|
||||||
|
|
||||||
|
getEnv(key: string, defaultValue?: string): string | undefined {
|
||||||
|
return process.env[key] || defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
setEnv(key: string, value: string): void {
|
||||||
|
process.env[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const osUtils = new OSUtils();
|
||||||
Reference in New Issue
Block a user