Added -L --list flag to see all task files with a very brief summary.?

This commit is contained in:
Storm Dragon
2025-08-13 03:24:43 -04:00
parent 9fdfee279f
commit c8745378c7

57
ged
View File

@@ -83,6 +83,7 @@ help() {
echo " ged -x 3 (--remove) # Permanently delete task 3"
echo " ged -p (--purge) # Remove tasks completed >30 days ago"
echo " ged -p 7 (--purge 7) # Remove tasks completed >7 days ago"
echo " ged -L (--list) # List all available task files"
exit 0
}
@@ -493,6 +494,58 @@ purge_old_tasks() {
fi
}
# List available task files
list_task_files() {
echo "Available task files:"
echo "===================="
# Check if tasks directory exists
if [[ ! -d "$TASKS_DIR" ]]; then
echo "No task files found. Create your first task to get started!"
return
fi
# Find all .db files in the tasks directory
local dbFiles=()
local fileFound=false
while IFS= read -r -d '' file; do
fileFound=true
local fileName=$(basename "$file" .db)
local fileSize=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null || echo "0")
local fileSizeKb=$((fileSize / 1024))
if [[ $fileSizeKb -eq 0 && $fileSize -gt 0 ]]; then
fileSizeKb="<1"
fi
# Get task counts for this file
local totalTasks pendingTasks completedTasks
totalTasks=$(sqlite3 "$file" "SELECT COUNT(*) FROM tasks;" 2>/dev/null || echo "0")
pendingTasks=$(sqlite3 "$file" "SELECT COUNT(*) FROM tasks WHERE status = 'pending';" 2>/dev/null || echo "0")
completedTasks=$(sqlite3 "$file" "SELECT COUNT(*) FROM tasks WHERE status = 'completed';" 2>/dev/null || echo "0")
# Mark current/default file
local marker=""
if [[ "$file" == "$TASKS_DB" ]]; then
marker=" (current)"
elif [[ "$fileName" == "tasks" ]]; then
marker=" (default)"
fi
printf " %-15s %3s pending, %3s done, %3s total (%s KB)%s\n" \
"$fileName" "$pendingTasks" "$completedTasks" "$totalTasks" "$fileSizeKb" "$marker"
done < <(find "$TASKS_DIR" -name "*.db" -print0 2>/dev/null | sort -z)
if [[ "$fileFound" == false ]]; then
echo "No task files found. Create your first task to get started!"
else
echo ""
echo "Usage: ged -f <filename> [command]"
echo "Example: ged -f work -s"
fi
}
# Array of command line arguments
declare -A command=(
[a]="List all tasks with their status (--all)."
@@ -501,6 +554,7 @@ declare -A command=(
[f:file_name]="Use specified database file (without .db extension)."
[h]="This help screen."
[l]="List pending tasks (same as no arguments)."
[L]="List available task files (--list)."
[p:days]="Remove completed tasks older than N days (--purge, default: 30)."
[r:task_number:new_date]="Reschedule task to new date."
[s]="Show task statistics (--stats)."
@@ -547,6 +601,9 @@ case "$1" in
"-l")
list_tasks
;;
"-L"|"--list")
list_task_files
;;
"--remove"|"--rm"|"-x")
if [[ -z "$2" ]]; then
echo "Error: Task number required for --remove option"