Syntax
Description
The--recent flag shows up to 10 recently visited branches, sorted by last access time (most recent first). This provides a quick way to return to branches you were recently working on.
Implementation
Theshow_recent function (src/main.rs:206-252) performs the following:
1. Load and sort branches
- Reads gitsw state from
.git/git-switch.json - Retrieves up to 10 most recently visited branches
- Sorts by
last_visitedtimestamp (descending)
2. Display format
- Current branch marked with
*and displayed in green/bold - Other branches shown with 2-space indent
- Numbered list
[1],[2], etc. - Shows
[stash]indicator if branch has stashed changes - Displays time since last visit
Output Format
marker:*for current branch,(two spaces) for othersindex: 1-based position number in dimmed textbranch_name: Green/bold if current, normal otherwisestash_indicator:[stash]in yellow if branch has stash, empty otherwisetime: Human-readable time since last visit (dimmed)
Example Output
With recent branches
Current branch not in recent list
No recent branches tracked
Time Format
Theformat_time_ago function (src/main.rs:569-586) converts timestamps:
| Duration | Format |
|---|---|
| < 1 minute | ”just now” |
| 1-59 minutes | ” min ago” |
| 1-23 hours | ” hour(s) ago” |
| 1 day | ”yesterday” |
| 2+ days | ” days ago” |
Stash Indicator
Displayed after branch name if the branch has a stash ID in gitsw state. Does not verify if stash still exists in Git.
Tracking Behavior
Branches are tracked when:- You switch to them using
gitsw - You switch away from them using
gitsw
last_visited timestamp is updated by the touch_branch function:
- Called before leaving current branch (src/main.rs:385)
- Called after switching to target branch (src/main.rs:513)
Maximum Branches
The function callsstate.recent_branches(10) to limit results to 10 branches. This is hardcoded in the implementation.
Use Cases
Quick navigation to recent work
Check for uncommitted work
The[stash] indicator shows branches with pending changes: