Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

65 copy from last registered day #66

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 27 additions & 1 deletion stup
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
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
Expand Down