Files
Netcatty/lib/localShell.cjs
陈大猫 cb4fb091aa [codex] Fix browser loading of shared rule files (#1002)
* Fix local shell browser import

* Fix command blocklist browser import
2026-05-18 21:05:33 +08:00

43 lines
1.4 KiB
JavaScript

"use strict";
const localShellRules = require("./localShellRules.json");
const POWERSHELL_SHELLS = new Set(localShellRules.powershellShells);
const CMD_SHELLS = new Set(localShellRules.cmdShells);
const FISH_SHELLS = new Set(localShellRules.fishShells);
const POSIX_SHELLS = new Set(localShellRules.posixShells);
const WSL_SHELLS = new Set(localShellRules.wslShells);
function getExecutableBaseName(filePath) {
const normalized = String(filePath || "").trim();
if (!normalized) return "";
const parts = normalized.split(/[\\/]/);
return (parts[parts.length - 1] || "").toLowerCase();
}
function detectLocalOs(platformLike) {
const platform = String(platformLike || "").toLowerCase();
if (platform.includes("mac")) return "macos";
if (platform.includes("win")) return "windows";
if (platform.includes("darwin")) return "macos";
return "linux";
}
function classifyLocalShellType(shellPath, platformLike) {
const shellName = getExecutableBaseName(shellPath);
if (POWERSHELL_SHELLS.has(shellName)) return "powershell";
if (CMD_SHELLS.has(shellName)) return "cmd";
if (FISH_SHELLS.has(shellName)) return "fish";
if (POSIX_SHELLS.has(shellName)) return "posix";
if (WSL_SHELLS.has(shellName)) return "posix";
if (!shellName) {
return detectLocalOs(platformLike) === "windows" ? "powershell" : "posix";
}
return "unknown";
}
module.exports = {
classifyLocalShellType,
detectLocalOs,
};