mirror of
https://github.com/github/awesome-copilot.git
synced 2026-08-26 18:45:12 +00:00
chore: publish from main
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
// Single-quoted arguments are literal in both POSIX shells and PowerShell; only the
|
||||
// escape for an embedded apostrophe differs, so callers pick the target shell.
|
||||
const SAFE_ARGUMENT = /^[A-Za-z0-9_\-./:@+=,]+$/;
|
||||
|
||||
export function detectShell(platform = "") {
|
||||
return /^win/i.test(String(platform)) ? "powershell" : "posix";
|
||||
}
|
||||
|
||||
export function quoteShellArg(value, shell = "posix") {
|
||||
const text = String(value ?? "");
|
||||
if (text === "") return "''";
|
||||
if (SAFE_ARGUMENT.test(text)) return text;
|
||||
const escaped = shell === "powershell" ? text.replace(/'/g, "''") : text.replace(/'/g, "'\\''");
|
||||
return `'${escaped}'`;
|
||||
}
|
||||
|
||||
export function formatShellCommand(parts, shell = "posix") {
|
||||
return parts.map((part) => quoteShellArg(part, shell)).join(" ");
|
||||
}
|
||||
Reference in New Issue
Block a user