commit 83bd956746a07563f35e86a4f948f34f37aef351
parent f523021567e36c5bd48d5be9b3b4034614998a80
Author: Henry Unite <unitehenry@gmail.com>
Date: Mon, 19 Oct 2026 19:54:51 +0000
refactor: move create.before shell hook registration to shell.ts
Diffstat:
| M | index.ts | | | 32 | ++------------------------------ |
1 file changed, 2 insertions(+), 30 deletions(-)
diff --git a/index.ts b/index.ts
@@ -5,6 +5,7 @@ import * as os from "node:os";
import * as path from "node:path";
import { registerPrompt } from "./prompt";
+import { registerShell } from "./shell";
const openpodRoot = path.join(os.homedir(), ".local", "share", "openpod");
const logDir = path.join(openpodRoot, ".log");
@@ -37,20 +38,6 @@ function isCommandAvailable(command: string): boolean {
}
}
-function getLimaName(dir: string): string | null {
- try {
- writeLog(`get lima name for ${openpodRoot} ${dir}`);
- const rel = path.relative(openpodRoot, dir);
- if (rel.startsWith("..") || path.isAbsolute(rel)) {
- return null;
- }
- const first = rel.split(path.sep).find((p) => p.length > 0);
- return first || null;
- } catch {
- return null;
- }
-}
-
async function cleanupOpenpod(sessionID: string): Promise<void> {
if (!sessionID || typeof sessionID !== "string") return;
@@ -128,22 +115,7 @@ export default Plugin.define({
}
await registerPrompt(ctx, { writeLog, openpodRoot });
-
- writeLog("registering create.before");
-
- await ctx.shell.hook("create.before", async (event) => {
- const limaName = getLimaName(event.cwd);
-
- if (limaName) {
- const originalCommand = event.command;
- const escapedCwd = event.cwd.replace(/'/g, "'\''");
- const escapedCmd = originalCommand.replace(/'/g, "'\''");
- event.command = `limactl shell --preserve-env --workdir='${escapedCwd}' ${limaName} bash -c '${escapedCmd}'`;
- writeLog(
- `redirected shell command for lima ${limaName} (cwd=${event.cwd})`,
- );
- }
- });
+ await registerShell(ctx, { writeLog, openpodRoot });
writeLog("registering commands");