When no issue ID is provided to `bd update` or `bd close`, use the last touched issue from the most recent create, update, show, or close operation. This addresses the common workflow where you create an issue and then immediately want to add more details (like changing priority from P2 to P4) without re-typing the issue ID. Implementation: - New file last_touched.go with Get/Set/Clear functions - Store last touched ID in .beads/last-touched (gitignored) - Track on create, update, show, and close operations - Allow update/close with zero args to use last touched (bd-s2t) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/steveyegge/beads/internal/beads"
|
|
)
|
|
|
|
const lastTouchedFile = "last-touched"
|
|
|
|
// GetLastTouchedID returns the ID of the last touched issue.
|
|
// Returns empty string if no last touched issue exists or the file is unreadable.
|
|
func GetLastTouchedID() string {
|
|
beadsDir := beads.FindBeadsDir()
|
|
if beadsDir == "" {
|
|
return ""
|
|
}
|
|
|
|
lastTouchedPath := filepath.Join(beadsDir, lastTouchedFile)
|
|
data, err := os.ReadFile(lastTouchedPath) // #nosec G304 -- path constructed from beadsDir
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
|
|
return strings.TrimSpace(string(data))
|
|
}
|
|
|
|
// SetLastTouchedID saves the ID of the last touched issue.
|
|
// Silently ignores errors (best-effort tracking).
|
|
func SetLastTouchedID(issueID string) {
|
|
if issueID == "" {
|
|
return
|
|
}
|
|
|
|
beadsDir := beads.FindBeadsDir()
|
|
if beadsDir == "" {
|
|
return
|
|
}
|
|
|
|
lastTouchedPath := filepath.Join(beadsDir, lastTouchedFile)
|
|
// Write with restrictive permissions (local-only state)
|
|
_ = os.WriteFile(lastTouchedPath, []byte(issueID+"\n"), 0600)
|
|
}
|
|
|
|
// ClearLastTouched removes the last touched file.
|
|
// Silently ignores errors.
|
|
func ClearLastTouched() {
|
|
beadsDir := beads.FindBeadsDir()
|
|
if beadsDir == "" {
|
|
return
|
|
}
|
|
|
|
lastTouchedPath := filepath.Join(beadsDir, lastTouchedFile)
|
|
_ = os.Remove(lastTouchedPath)
|
|
}
|