Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 9, 2025

This PR adds a -t flag to sort files by modification time with newest files first, providing better compatibility with GNU coreutils ls -t command.

Currently, users need to use --sort time to achieve time-based sorting. This change adds the more familiar and concise -t flag that behaves identically to the existing --sort time functionality.

Changes Made

  • Added -t flag definition in /internal/cli/sort.go that calls sorter.ByTimeAscend(timeType[0]) to sort by modification time (newest first)
  • Updated help text in /internal/cli/g.go to include the new flag in the SORTING section
  • The implementation reuses existing sorting infrastructure and follows the same pattern as other single-character sorting flags (-S, -X, -U)

Usage Examples

# Before: verbose flag required
g --sort time

# After: concise flag available
g -t

# Both produce identical output (newest files first)
g -t -l
g --sort time -l

The -t flag works with all existing options and formats, maintaining full compatibility with the current functionality while providing the familiar interface that users expect from standard ls command.

Fixes #259.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Sep 9, 2025
Copy link
Contributor Author

Copilot AI commented Sep 9, 2025

@equationzhao 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@pull-request-size pull-request-size bot added size/S and removed size/XS labels Sep 9, 2025
Copilot AI changed the title [WIP] [FEAT] Add -t flag for sorting by time Add -t flag for sorting by time Sep 9, 2025
Copilot AI requested a review from equationzhao September 9, 2025 08:08
@equationzhao equationzhao marked this pull request as ready for review September 9, 2025 09:08
Copilot AI review requested due to automatic review settings September 9, 2025 09:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a -t flag for time-based sorting to improve compatibility with GNU coreutils ls -t command. The flag provides a concise alternative to the existing --sort time option.

  • Adds -t flag that sorts files by modification time with newest files first
  • Updates help documentation to include the new flag in the SORTING section
  • Maintains full compatibility with existing functionality while providing familiar interface

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/cli/sort.go Adds new -t BoolFlag with time sorting action
internal/cli/g.go Updates help text to document the new -t flag

@equationzhao equationzhao merged commit eaa4adb into master Sep 9, 2025
11 checks passed
@equationzhao equationzhao deleted the copilot/add-flag-for-time-sorting branch September 9, 2025 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Add -t flag for sorting by time

2 participants