/** * Small shell-command helpers shared by the prompt signals and the activity * map: program names, shell-wrapper unwrapping, quoting, and splitting a * command line into the commands it runs. * * These read command *structure* only (which programs run); callers decide * what may be shown. Pure: no filesystem access. Browser-safe. * * @module shellCommand */ export const POSIX_SHELLS: ReadonlySet = new Set([ 'sh', 'bash', 'zsh', 'dash', 'fish', 'ksh', ]); export const POWERSHELLS: ReadonlySet = new Set(['pwsh', 'powershell']); /** `/usr/bin/zsh` → `zsh`, `C:\Windows\System32\cmd.exe` → `cmd`. */ export function programName(argv0: string): string { return (argv0.split(/[\\/]/).pop() ?? argv0).toLowerCase().replace(/\.exe$/, ''); } /** An argv element as a POSIX shell would need it written. */ export function shellQuote(arg: string): string { if (/^[A-Za-z0-9_@%+=:,./-]+$/.test(arg)) return arg; return `'${arg.replace(/'/g, `'\\''`)}'`; } /** * The command a call ran, as a person would type it: a string as is; for an * argv, the script of a shell wrapper (`bash -lc