Fix Logseq Task List query block pattern #1
1 changed files with 77 additions and 18 deletions
|
|
@ -17,6 +17,9 @@
|
||||||
# ./run_full_cleanup.sh ~/notes_test/journals/2026_10_23.md
|
# ./run_full_cleanup.sh ~/notes_test/journals/2026_10_23.md
|
||||||
# ./run_full_cleanup.sh -r ~/notes_test/journals/
|
# ./run_full_cleanup.sh -r ~/notes_test/journals/
|
||||||
#
|
#
|
||||||
|
# Note: When processing directories, the most recent file (by filename date) is
|
||||||
|
# automatically excluded to avoid modifying today's active journal.
|
||||||
|
#
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|
@ -24,6 +27,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
DRY_RUN=""
|
DRY_RUN=""
|
||||||
RECURSIVE=""
|
RECURSIVE=""
|
||||||
TARGET=""
|
TARGET=""
|
||||||
|
SKIP_MOST_RECENT=true
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
|
|
@ -36,6 +40,10 @@ while [[ $# -gt 0 ]]; do
|
||||||
RECURSIVE="-r"
|
RECURSIVE="-r"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--include-most-recent)
|
||||||
|
SKIP_MOST_RECENT=false
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
TARGET="$1"
|
TARGET="$1"
|
||||||
shift
|
shift
|
||||||
|
|
@ -45,34 +53,85 @@ done
|
||||||
|
|
||||||
if [ -z "$TARGET" ]; then
|
if [ -z "$TARGET" ]; then
|
||||||
echo "Error: No target path specified"
|
echo "Error: No target path specified"
|
||||||
echo "Usage: $0 [--dry-run] [-r] <path>"
|
echo "Usage: $0 [--dry-run] [-r] [--include-most-recent] <path>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Determine if target is a directory
|
||||||
|
IS_DIR=false
|
||||||
|
if [ -d "$TARGET" ]; then
|
||||||
|
IS_DIR=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Find and exclude most recent file if processing a directory
|
||||||
|
EXCLUDE_FILE=""
|
||||||
|
if [ "$IS_DIR" = true ] && [ "$SKIP_MOST_RECENT" = true ]; then
|
||||||
|
# Find the most recent file by filename date (format: YYYY_MM_DD.md or YYYY-MM-DD.md)
|
||||||
|
EXCLUDE_FILE=$(find "$TARGET" -maxdepth 1 -name '*.md' -type f | \
|
||||||
|
sed 's/.*\///' | sed 's/_/-/g' | sort -r | head -1)
|
||||||
|
if [ -n "$EXCLUDE_FILE" ]; then
|
||||||
|
echo "Excluding most recent file: $EXCLUDE_FILE"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
echo "Logseq Full Cleanup"
|
echo "Logseq Full Cleanup"
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
echo "Target: $TARGET"
|
echo "Target: $TARGET"
|
||||||
[ -n "$DRY_RUN" ] && echo "Mode: DRY RUN (no changes will be made)"
|
[ -n "$DRY_RUN" ] && echo "Mode: DRY RUN (no changes will be made)"
|
||||||
|
[ -n "$EXCLUDE_FILE" ] && echo "Excluding: $EXCLUDE_FILE"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Step 1: Remove Task List query blocks
|
# Create a temporary file list if excluding most recent
|
||||||
echo "Step 1/3: Removing Task List query blocks..."
|
if [ -n "$EXCLUDE_FILE" ]; then
|
||||||
echo "-------------------------------------------"
|
TEMP_LIST=$(mktemp)
|
||||||
python3 "$SCRIPT_DIR/clean_task_lists.py" $DRY_RUN $RECURSIVE "$TARGET"
|
find "$TARGET" -maxdepth 1 -name '*.md' -type f | grep -v "$(basename "$EXCLUDE_FILE")" > "$TEMP_LIST"
|
||||||
echo ""
|
|
||||||
|
# Process each file in the list
|
||||||
# Step 2: Remove empty bullet lines
|
while IFS= read -r file; do
|
||||||
echo "Step 2/3: Removing empty bullet lines..."
|
# Step 1: Remove Task List query blocks
|
||||||
echo "-------------------------------------------"
|
echo "Step 1/3: Removing Task List query blocks..."
|
||||||
python3 "$SCRIPT_DIR/clean_empty_bullets.py" $DRY_RUN $RECURSIVE "$TARGET"
|
echo "-------------------------------------------"
|
||||||
echo ""
|
python3 "$SCRIPT_DIR/clean_task_lists.py" $DRY_RUN "$file"
|
||||||
|
echo ""
|
||||||
# Step 3: Ensure single trailing newline
|
|
||||||
echo "Step 3/3: Ensuring single trailing newline..."
|
# Step 2: Remove empty bullet lines
|
||||||
echo "-------------------------------------------"
|
echo "Step 2/3: Removing empty bullet lines..."
|
||||||
python3 "$SCRIPT_DIR/ensure_newline_ending.py" $DRY_RUN $RECURSIVE "$TARGET"
|
echo "-------------------------------------------"
|
||||||
echo ""
|
python3 "$SCRIPT_DIR/clean_empty_bullets.py" $DRY_RUN "$file"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Step 3: Ensure single trailing newline
|
||||||
|
echo "Step 3/3: Ensuring single trailing newline..."
|
||||||
|
echo "-------------------------------------------"
|
||||||
|
python3 "$SCRIPT_DIR/ensure_newline_ending.py" $DRY_RUN "$file"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "---"
|
||||||
|
echo ""
|
||||||
|
done < "$TEMP_LIST"
|
||||||
|
|
||||||
|
rm -f "$TEMP_LIST"
|
||||||
|
else
|
||||||
|
# Run on target directly (single file or no exclusion)
|
||||||
|
# Step 1: Remove Task List query blocks
|
||||||
|
echo "Step 1/3: Removing Task List query blocks..."
|
||||||
|
echo "-------------------------------------------"
|
||||||
|
python3 "$SCRIPT_DIR/clean_task_lists.py" $DRY_RUN $RECURSIVE "$TARGET"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Step 2: Remove empty bullet lines
|
||||||
|
echo "Step 2/3: Removing empty bullet lines..."
|
||||||
|
echo "-------------------------------------------"
|
||||||
|
python3 "$SCRIPT_DIR/clean_empty_bullets.py" $DRY_RUN $RECURSIVE "$TARGET"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Step 3: Ensure single trailing newline
|
||||||
|
echo "Step 3/3: Ensuring single trailing newline..."
|
||||||
|
echo "-------------------------------------------"
|
||||||
|
python3 "$SCRIPT_DIR/ensure_newline_ending.py" $DRY_RUN $RECURSIVE "$TARGET"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
echo "Cleanup complete!"
|
echo "Cleanup complete!"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue