Refactor to customize shell integration per shell

This commit is contained in:
Sander Declerck 2025-07-17 16:35:03 +02:00
parent 21cdefadde
commit fe1ca396b4
No known key found for this signature in database
16 changed files with 1302 additions and 780 deletions

View file

@ -0,0 +1,45 @@
import {
addLineToFile,
doesExecutableExistOnSystem,
execAndGetOutput,
removeLinesMatchingPattern,
} from "../helpers.js";
const shellName = "PowerShell Core";
const executableName = "pwsh";
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,
};