UNPKG

worktree-tool

Version:

A command-line tool for managing Git worktrees with integrated tmux/shell session management

132 lines 3.29 kB
import { execSync } from "child_process"; import { PlatformError } from "../utils/errors.js"; /** * Detect the current platform information */ export function detectPlatform() { const os = detectOS(); const hasTmux = checkTmuxAvailableSync(); const shellType = detectShell(); return { os, hasTmux, shellType, }; } /** * Detect the operating system */ function detectOS() { const { platform } = process; switch (platform) { case "win32": return "windows"; case "darwin": return "macos"; case "linux": return "linux"; default: throw new PlatformError(`Unsupported platform: ${platform}`); } } /** * Check if tmux is available on the system */ export function checkTmuxAvailable() { // Check for test environment variable to disable tmux if (process.env.WTT_DISABLE_TMUX === "true") { return false; } // Windows doesn't have tmux if (process.platform === "win32") { return false; } try { execSync("which tmux", { stdio: "ignore" }); return true; } catch { return false; } } /** * Synchronous version of tmux check for platform detection */ function checkTmuxAvailableSync() { // Check for test environment variable to disable tmux if (process.env.WTT_DISABLE_TMUX === "true") { return false; } // Windows doesn't have tmux if (process.platform === "win32") { return false; } try { execSync("which tmux", { stdio: "ignore" }); return true; } catch { return false; } } /** * Detect the current shell type */ export function detectShell() { // Check environment variables const shell = process.env.SHELL ?? ""; // Unix-like shell detection if (shell.includes("zsh")) { return "zsh"; } if (shell.includes("bash")) { return "bash"; } // Windows shell detection if (process.platform === "win32") { // Default to PowerShell on Windows return "powershell"; } // Default fallbacks if (process.platform === "darwin") { // macOS defaults to zsh since Catalina return "zsh"; } // Linux and others default to bash return "bash"; } /** * Get the shell executable path */ export function getShellPath(shellType) { switch (shellType) { case "bash": return process.platform === "win32" ? "bash.exe" : "/bin/bash"; case "zsh": return "/bin/zsh"; case "powershell": return "powershell.exe"; default: throw new PlatformError(`Unknown shell type: ${shellType}`); } } /** * Check if running inside a CI environment */ export function isCI() { return !!(process.env.CI ?? process.env.CONTINUOUS_INTEGRATION ?? process.env.GITHUB_ACTIONS ?? process.env.GITLAB_CI ?? process.env.CIRCLECI ?? process.env.TRAVIS ?? process.env.JENKINS_URL ?? process.env.TEAMCITY_VERSION); } /** * Get platform-specific path separator */ export function getPathSeparator() { return process.platform === "win32" ? ";" : ":"; } //# sourceMappingURL=detector.js.map