diff --git a/src/utils/osUtils.ts b/src/utils/osUtils.ts new file mode 100644 index 0000000..7b1fd0f --- /dev/null +++ b/src/utils/osUtils.ts @@ -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 { + 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();