bucket inboxes by target for excessive automoving

master
Bel LaPointe 2023-11-14 18:36:00 -07:00
parent ba81940b0b
commit 9b482d45b4
1 changed files with 14 additions and 10 deletions

View File

@ -12,8 +12,8 @@ import (
"syscall"
"time"
"github.com/google/uuid"
"gitea.inhome.blapointe.com/gogs/pttodo/pttodo"
"github.com/google/uuid"
"gopkg.in/yaml.v2"
)
@ -135,11 +135,12 @@ func inEditableDirAsTodos(filepaths []string) (string, error) {
}
func copyTodoToDir(d string, filepaths []string) error {
inboxes := []string{}
inboxes := map[string][]string{}
for _, target := range filepaths {
p := path.Join(d, path.Base(target))
if strings.Contains(path.Base(target), ".todo.") {
inboxes = append(inboxes, target)
p := path.Join(d, strings.Split(path.Base(p), ".todo")[0])
inboxes[p] = append(inboxes[p], target)
continue
}
if root, err := pttodo.NewRootFromFile(target); err != nil {
@ -150,15 +151,18 @@ func copyTodoToDir(d string, filepaths []string) error {
return err
}
}
for p, inboxes := range inboxes {
inboxRoot := pttodo.Root{}
for _, inbox := range inboxes {
target := path.Join(path.Dir(inbox), strings.Split(path.Base(inbox), ".todo.")[0])
p := path.Join(d, path.Base(target))
root, err := pttodo.NewRootFromFile(p)
subInboxRoot, err := pttodo.NewRootFromFile(inbox)
if err != nil {
return err
}
inboxRoot, err := pttodo.NewRootFromFile(inbox)
inboxRoot.MergeIn(pttodo.Root{Todo: subInboxRoot.Todo})
inboxRoot.MergeIn(pttodo.Root{Todo: subInboxRoot.Scheduled})
}
root, err := pttodo.NewRootFromFile(p)
if err != nil {
return err
}