mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 20:20:49 +00:00
Refactor to customize shell integration per shell
This commit is contained in:
parent
21cdefadde
commit
fe1ca396b4
16 changed files with 1302 additions and 780 deletions
45
src/shell-integration/supported-shells/windowsPowershell.js
Normal file
45
src/shell-integration/supported-shells/windowsPowershell.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import {
|
||||
addLineToFile,
|
||||
doesExecutableExistOnSystem,
|
||||
execAndGetOutput,
|
||||
removeLinesMatchingPattern,
|
||||
} from "../helpers.js";
|
||||
|
||||
const shellName = "Windows PowerShell";
|
||||
const executableName = "powershell";
|
||||
const startupFileCommand = "echo $PROFILE";
|
||||
|
||||
function isInstalled() {
|
||||
return doesExecutableExistOnSystem(executableName);
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
const startupFile = execAndGetOutput(startupFileCommand, executableName);
|
||||
|
||||
// Removes all aliases starting with "Set-Alias npm=", "Set-Alias npx=", or "Set-Alias yarn="
|
||||
// This will remove the safe-chain aliases for npm, npx, and yarn commands.
|
||||
removeLinesMatchingPattern(startupFile, /^Set-Alias\s+(npm|npx|yarn)\s+/);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function setup(tools) {
|
||||
const startupFile = execAndGetOutput(startupFileCommand, executableName);
|
||||
teardown();
|
||||
|
||||
for (const { tool, aikidoCommand } of tools) {
|
||||
addLineToFile(
|
||||
startupFile,
|
||||
`Set-Alias ${tool} ${aikidoCommand} # Safe-chain alias for ${tool}`
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export default {
|
||||
name: shellName,
|
||||
isInstalled,
|
||||
setup,
|
||||
teardown,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue