UNPKG

super-shell-mcp

Version:

MCP server for executing shell commands across multiple platforms

110 lines 3.58 kB
import * as fs from 'fs'; /** * Supported platform types */ export var PlatformType; (function (PlatformType) { PlatformType["WINDOWS"] = "windows"; PlatformType["MACOS"] = "macos"; PlatformType["LINUX"] = "linux"; PlatformType["UNKNOWN"] = "unknown"; })(PlatformType || (PlatformType = {})); /** * Detect the current platform * @returns The detected platform type */ export function detectPlatform() { const platform = process.platform; if (platform === 'win32') return PlatformType.WINDOWS; if (platform === 'darwin') return PlatformType.MACOS; if (platform === 'linux') return PlatformType.LINUX; return PlatformType.UNKNOWN; } /** * Get the default shell for the current platform * @returns Path to the default shell */ export function getDefaultShell() { const platform = detectPlatform(); switch (platform) { case PlatformType.WINDOWS: return process.env.COMSPEC || 'cmd.exe'; case PlatformType.MACOS: return '/bin/zsh'; case PlatformType.LINUX: return process.env.SHELL || '/bin/bash'; default: return process.env.SHELL || '/bin/sh'; } } /** * Validate if a shell path exists and is executable * @param shellPath Path to the shell * @returns True if the shell is valid */ export function validateShellPath(shellPath) { try { return fs.existsSync(shellPath) && fs.statSync(shellPath).isFile(); } catch (error) { return false; } } /** * Get shell suggestions for each platform * @returns Record of platform types to array of suggested shells */ export function getShellSuggestions() { return { [PlatformType.WINDOWS]: ['cmd.exe', 'powershell.exe', 'pwsh.exe'], [PlatformType.MACOS]: ['/bin/zsh', '/bin/bash', '/bin/sh'], [PlatformType.LINUX]: ['/bin/bash', '/bin/sh', '/bin/zsh'], [PlatformType.UNKNOWN]: ['/bin/sh'] }; } /** * Get common locations for shells on the current platform * @returns Array of common shell locations */ export function getCommonShellLocations() { const platform = detectPlatform(); switch (platform) { case PlatformType.WINDOWS: return [ process.env.COMSPEC || 'C:\\Windows\\System32\\cmd.exe', 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', 'C:\\Program Files\\PowerShell\\7\\pwsh.exe' ]; case PlatformType.MACOS: return ['/bin/zsh', '/bin/bash', '/bin/sh']; case PlatformType.LINUX: return ['/bin/bash', '/bin/sh', '/usr/bin/bash', '/usr/bin/zsh']; default: return ['/bin/sh']; } } /** * Get helpful message for shell configuration * @returns A helpful message with shell configuration guidance */ export function getShellConfigurationHelp() { const platform = detectPlatform(); const suggestions = getShellSuggestions()[platform]; const locations = getCommonShellLocations(); let message = 'Shell Configuration Help:\n\n'; message += `Detected platform: ${platform}\n\n`; message += 'Suggested shells for this platform:\n'; suggestions.forEach(shell => { message += `- ${shell}\n`; }); message += '\nCommon shell locations on this platform:\n'; locations.forEach(location => { message += `- ${location}\n`; }); message += '\nTo configure a custom shell, provide the full path to the shell executable.'; return message; } //# sourceMappingURL=platform-utils.js.map