From c41a045ddfa8ea744afd71753d83caccbc8f93df Mon Sep 17 00:00:00 2001 From: Giannis Poulis Date: Fri, 25 Mar 2022 15:14:50 +0200 Subject: [PATCH 1/3] Allow copy of previous working if day not found --- stup | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/stup b/stup index da4abc6..c59841e 100755 --- a/stup +++ b/stup @@ -331,7 +331,33 @@ execute_copy() if ! [ -s "$copy_from_file" ]; then print_error "Failed to find notes for category $CATEGORY on $(display_date $FROM_AT). Looked up for file: $copy_from_file" - exit 1 + read -e -p "Do you want to copy the last notes added in this category before $(display_date $FROM_AT) with stup? (y/n) " copy_from_last_entries + + if [ "$(resolve_boolean "$copy_from_last_entries")" = "true" ]; then + if [[ $CATEGORY ]]; then + copy_from_root_path="$REPOSITORY_ROOT/$CATEGORY" + else + copy_from_root_path="$REPOSITORY_ROOT" + fi + + # Find last date <= of the copy from given + IFS=$'\n' read -r -d '' -a date < <(find "$copy_from_root_path" -type f | grep -Po '[0-9]{4}-[0-9]{2}-[0-9]{2}(?=\.md$)' | awk -v date="$FROM_AT" '$1 < date { print }' | sort | uniq | tail -1) + + if [ -z "$date" ]; then + print_error "Failed to find notes for category $CATEGORY before $(display_date $FROM_AT)." + exit 1 + fi + + FROM_AT=$date + + YEAR=$(echo $date | cut -d- -f1) + MONTH=$(echo $date | cut -d- -f2) + DAY=$(echo $date | cut -d- -f3) + + copy_from_file="$copy_from_root_path/$YEAR/$MONTH/$YEAR-$MONTH-$DAY.md" + else + exit 0 + fi fi if [ "$copy_from_file" = $target_file ]; then From aca3bae964eb6c758a356536c3dd2a00f175af07 Mon Sep 17 00:00:00 2001 From: Giannis Poulis Date: Fri, 25 Mar 2022 19:56:39 +0200 Subject: [PATCH 2/3] Add latest date copy from functionality to README --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index b9ab56c..7d6c0ab 100644 --- a/README.md +++ b/README.md @@ -549,6 +549,19 @@ $ stup copy --from 2020-01-15 --to 2020-02-01 $ stup copy --to tomorrow -c blocking ``` +If no notes are found on the `--from` date, stup will prompt the user to copy from the last date before that date: +``` +Failed to find notes for category personal on Thursday March 24, 2022. Looked up for file: /path/to/.stup/personal/2022/03/2022-03-24.md +Do you want to copy the last notes added in this category before Thursday March 24, 2022 with stup? (y/n) y +About to copy notes from Wednesday March 23, 2022 to Friday March 25, 2022 for category personal + +- Worked on some PRs + + +>>> Copy this note [y,n,q,a]?: +``` + + ### Add a new category To add a new category to save notes into use the following command. From 355a99510c75d690316e3c19ced9518275ccd608 Mon Sep 17 00:00:00 2001 From: Giannis Poulis Date: Fri, 25 Mar 2022 22:07:36 +0200 Subject: [PATCH 3/3] fixup! Allow copy of previous working if day not found --- stup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stup b/stup index c59841e..3d9d683 100755 --- a/stup +++ b/stup @@ -340,7 +340,7 @@ execute_copy() copy_from_root_path="$REPOSITORY_ROOT" fi - # Find last date <= of the copy from given + # Find last date before the copy_from_date given IFS=$'\n' read -r -d '' -a date < <(find "$copy_from_root_path" -type f | grep -Po '[0-9]{4}-[0-9]{2}-[0-9]{2}(?=\.md$)' | awk -v date="$FROM_AT" '$1 < date { print }' | sort | uniq | tail -1) if [ -z "$date" ]; then