#!/bin/bash # 每日回顾整理脚本 # 功能:将TODO.md中已完成的任务移动到昨天的每日回顾中 set -e WORK_DIR="/home/starmen1265/work/zq" TODO_FILE="$WORK_DIR/01.待办/TODO.md" REVIEW_DIR="$WORK_DIR/40.归档/每日回顾" # 获取昨天的日期(格式:YYYY-MM-DD) YESTERDAY=$(date -d "yesterday" +%Y-%m-%d) REVIEW_FILE="$REVIEW_DIR/$YESTERDAY.md" # 切换到工作目录 cd "$WORK_DIR" # 如果没有已完成的任务,直接退出 if ! grep -q "\[x\]" "$TODO_FILE"; then echo "No completed tasks found. Exiting." exit 0 fi # 提取已完成的任务(保留标题结构) # 读取TODO.md,提取所有包含[x]的行及其所属标题 COMPLETED_TASKS=$(awk ' /^#/ { current_section = $0 } /\[x\]/ { if (current_section != last_section) { print current_section last_section = current_section } print $0 } ' "$TODO_FILE") # 如果每日回顾文件不存在,创建它 if [ ! -f "$REVIEW_FILE" ]; then touch "$REVIEW_FILE" fi # 将完成的任务追加到每日回顾文件(去掉✅及后面的日期) echo "$COMPLETED_TASKS" | sed 's/ ✅ [0-9-]*$//' >> "$REVIEW_FILE" # 从TODO.md中删除已完成的任务行 sed -i '/\[x\]/d' "$TODO_FILE" # 清理TODO.md中的空标题(标题下没有任务的情况) awk ' /^#/ { if (section_content != "") { print section_header print section_content } section_header = $0 section_content = "" next } !/^#/ && $0 != "" { section_content = section_content "\n" $0 } END { if (section_content != "") { print section_header print section_content } } ' "$TODO_FILE" > "$TODO_FILE.tmp" && mv "$TODO_FILE.tmp" "$TODO_FILE" # 提交git变更 git add "$TODO_FILE" "$REVIEW_DIR/$YESTERDAY.md" git commit -m "每日回顾整理:$YESTERDAY" || echo "No changes to commit" echo "Daily review completed for $YESTERDAY"