Zsh: check if safe-chain is installed before running it.

This commit is contained in:
Sander Declerck 2025-07-17 16:40:09 +02:00
parent fe1ca396b4
commit 09300eade6
No known key found for this signature in database
4 changed files with 177 additions and 45 deletions

View file

@ -2,6 +2,10 @@ import chalk from "chalk";
import { ui } from "../environment/userInteraction.js";
import { detectShells } from "./shellDetection.js";
import { knownAikidoTools } from "./helpers.js";
import fs from "fs";
import os from "os";
import path from "path";
import { fileURLToPath } from "url";
/**
* Loops over the detected shells and calls the setup function for each.
@ -13,6 +17,8 @@ export async function setup() {
);
ui.emptyLine();
copyStartupFiles();
try {
const shells = detectShells();
if (shells.length === 0) {
@ -72,3 +78,23 @@ function setupShell(shell) {
return success;
}
function copyStartupFiles() {
const startupFiles = ["init-zsh.sh"];
for (const file of startupFiles) {
const targetPath = path.join(os.homedir(), ".safe-chain", "scripts", file);
// Create target directory if it doesn't exist
const targetDir = targetPath.substring(0, targetPath.lastIndexOf("/"));
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
// Use absolute path for source
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const sourcePath = path.resolve(__dirname, "startup-scripts", file);
fs.copyFileSync(sourcePath, targetPath);
}
}