Store and display prompt in session; improve list formatting with tilde paths and prompt column
This commit is contained in:
parent
8b276036bf
commit
cf28eec718
16
src/cli.ts
16
src/cli.ts
|
|
@ -124,10 +124,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) {
|
||||
|
|
@ -167,10 +169,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 ?? ""}`)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -191,6 +198,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 })
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ export interface Session {
|
|||
branch: string
|
||||
worktree: string
|
||||
created_at: string
|
||||
prompt?: string
|
||||
}
|
||||
|
||||
export interface State {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user