@@ -371,12 +371,14 @@ export function registerCredsCommands(parent: Command, options: RegisterOptions
371371 . command ( "unlock" )
372372 . description ( "start a session" )
373373 . addHelpText ( "after" , examples ( `
374- eval "$($CLI unlock)" unlock for this shell only (nothing written to disk)
375- $CLI unlock --persist --timeout 30 unlock for scripts for 30 minutes; \`lock\` ends it` ) )
376- . option ( "--persist" , "write the session to a 0600 file instead of printing a token" )
374+ $CLI unlock unlock interactively for 15 minutes; \`lock\` ends it
375+ eval "$($CLI unlock --shell)" export a session into this shell (nothing written to disk)
376+ $CLI unlock --persist --timeout 30 choose a persisted session lifetime` ) )
377+ . option ( "--persist" , "write the session to a 0600 file (the default in an interactive terminal)" )
378+ . option ( "--shell" , "print an export command for the current shell instead of writing a session file" )
377379 . option ( "--password-stdin" , "read the master password from stdin" )
378380 . option ( "--timeout <minutes>" , "session lifetime when persisted" , ( v : string ) => Number . parseInt ( v , 10 ) , 15 )
379- . action ( async function ( this : Command , opts : { persist ?: boolean ; timeout : number ; passwordStdin ?: boolean } ) {
381+ . action ( async function ( this : Command , opts : { persist ?: boolean ; shell ?: boolean ; timeout : number ; passwordStdin ?: boolean } ) {
380382 await run ( async ( ) => {
381383 const store = storeFor ( this ) ;
382384 const meta = requireMeta ( store ) ;
@@ -392,7 +394,11 @@ export function registerCredsCommands(parent: Command, options: RegisterOptions
392394 }
393395 store . appendAudit ( auditEvent ( { action : "vault.unlock" , namespace : meta . namespace , profile : meta . profile } ) ) ;
394396
395- if ( opts . persist ) {
397+ // A plain interactive `unlock` should do what people expect: unlock
398+ // the vault for subsequent commands. The export-only behavior remains
399+ // available behind --shell and for non-interactive/scripted use.
400+ const persist = Boolean ( opts . persist ) || ( ! opts . shell && Boolean ( process . stdin . isTTY ) && ! opts . passwordStdin ) ;
401+ if ( persist ) {
396402 const path = persistSession ( userKey , opts . timeout , store . baseDir ) ;
397403 process . stdout . write ( `Session written to ${ path } , expiring in ${ opts . timeout } minutes.\n` ) ;
398404 process . stdout . write (
0 commit comments