This document describes the new --order-by feature that allows users to sort tasks by different fields.
The --order-by option enables users to sort their tasks by various fields including due date, creation date, modification date, priority, and title. This feature is available in both the regular gtasks list command and the interactive mode.
The following sort options are available with the --order-by flag:
due- Sort by due date (tasks without due dates appear at the end)created- Sort by creation datemodified- Sort by last modification datepriority- Sort by priority (critical, high, medium, low)title- Sort by title alphabetically
# Sort tasks by due date
gtasks list --order-by due
# Sort tasks by title
gtasks list --order-by title
# Sort tasks by priority
gtasks list --order-by priority
# Combine with other filters
gtasks list "My Tasks" --status pending --order-by due
# Sort tasks by creation date
gtasks list --order-by created# Start interactive mode with pre-sorted tasks
gtasks interactive -- list --order-by due
# Use within interactive mode
list --order-by title
list "Work" --order-by priorityThe sorting functionality is implemented in the _sort_tasks function in list.py. The function handles special cases for different data types:
- Due date sorting places tasks without due dates at the end
- Priority sorting follows the order: critical, high, medium, low
- Date-based sorting handles None values appropriately
- Title sorting is case-insensitive
- Command Line Interface: The
--order-byoption is added to thelistcommand using Click's option decorator - Interactive Mode: The option is parsed in both initial commands and during interactive session
- Initial Commands Handler: Supports the
--order-byoption for pre-sorted initial views
- Use
duesorting to focus on upcoming deadlines - Use
createdsorting to see recently added tasks - Use
modifiedsorting to see recently updated tasks - Use
prioritysorting to focus on high-priority items - Use
titlesorting for alphabetical organization
-
View all tasks sorted by due date:
gtasks list --order-by due
-
View high-priority tasks sorted by priority level:
gtasks list --priority high --order-by priority
-
View tasks in alphabetical order:
gtasks list --order-by title
-
In interactive mode, start with tasks sorted by modification date:
gtasks interactive -- list --order-by modified
This feature enhances the usability of the GTasks CLI by allowing users to organize their tasks in the most meaningful way for their current context.