diff --git a/src/cli.ts b/src/cli.ts index 68065aa..12a4e5d 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -125,10 +125,12 @@ program process.exit(1) } + const effectivePrompt = opts.print || prompt await state.setSession(root, { branch, worktree: worktreeAbs, created_at: new Date().toISOString(), + ...(effectivePrompt ? { prompt: effectivePrompt } : {}), }) if (opts.print) { @@ -168,10 +170,15 @@ program return } + const home = homedir() + const tilde = (p: string) => p.startsWith(home) ? "~" + p.slice(home.length) : p + const branchWidth = Math.max(6, ...sessions.map((s) => s.branch.length)) - console.log(`${"BRANCH".padEnd(branchWidth)} WORKTREE`) + const worktreeWidth = Math.max(8, ...sessions.map((s) => tilde(s.worktree).length + 1)) + console.log(`${"BRANCH".padEnd(branchWidth)} ${"WORKTREE".padEnd(worktreeWidth)} PROMPT`) for (const s of sessions) { - console.log(`${s.branch.padEnd(branchWidth)} ${s.worktree}/`) + const wt = tilde(s.worktree) + "/" + console.log(`${s.branch.padEnd(branchWidth)} ${wt.padEnd(worktreeWidth)} ${s.prompt ?? ""}`) } }) @@ -193,6 +200,11 @@ program process.exit(1) } + const effectivePrompt = opts.print || prompt + if (effectivePrompt) { + await state.setSession(root, { ...session, prompt: effectivePrompt }) + } + const spin = spinner("Starting container") await vm.ensure((msg) => { spin.text = msg }) diff --git a/src/state.ts b/src/state.ts index 09c34f6..40bb41c 100644 --- a/src/state.ts +++ b/src/state.ts @@ -4,6 +4,7 @@ export interface Session { branch: string worktree: string created_at: string + prompt?: string } export interface State {