Skip to content

feat: add --sort/-s flag to sort by date - #57

Merged
llimllib merged 4 commits into
mainfrom
sort-by-git-modified
May 28, 2026
Merged

feat: add --sort/-s flag to sort by date#57
llimllib merged 4 commits into
mainfrom
sort-by-git-modified

Conversation

@llimllib

@llimllib llimllib commented May 28, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a --sort / -s flag that sorts files by their last git commit timestamp, most recent first.

Behavior

  • Files are sorted by the unix timestamp of their last modifying commit (descending)
  • When timestamps are equal, files fall back to alphabetical ordering
  • Files without a date (ignored I, untracked ??, .git *, newly added A) are placed at the bottom, sorted alphabetically among themselves
  • Without --sort, the existing alphabetical sort is unchanged

Implementation

  • Added commitTime int64 field to the File struct
  • Added %at (author date as unix timestamp) to the git log format string — negligible parsing cost (strconv.ParseInt)
  • Sort uses the precise unix timestamp rather than the display date string, so files modified on the same day are correctly ordered by commit time

Example

image

llimllib added 2 commits May 26, 2026 12:57
Sort files by git commit timestamp (descending, most recent first).
Files without a date (ignored, untracked, .git) are placed at the
bottom in alphabetical order.

Uses the unix timestamp (%at) from git log for precise sub-day
ordering when multiple files share the same date.
@llimllib llimllib changed the title feat: add --sort/-s flag to sort files by last modification date feat: add --sort/-s flag to sort by date May 28, 2026
llimllib added 2 commits May 28, 2026 15:50
Instead of using git's --date=format (which uses the author's local
timezone), we now format the display date from the unix timestamp in
UTC. This avoids confusing situations where a commit made later could
show an earlier date due to timezone differences.

Also simplifies the git log format string by removing %ad.
Extract sortFilesByDate and sortFilesByName into named functions for
testability. Add tests covering:
- Descending date sort with undated files at the bottom
- Same-timestamp fallback to alphabetical order
- Undated files (ignored, untracked, .git) grouped at bottom
- Case-insensitive alphabetical sort
@llimllib
llimllib merged commit 1f2e7ab into main May 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant