original.yaml has just todo, merge against .original.yaml so mobile edits still get a history
This commit is contained in:
13
cmd/edit.go
13
cmd/edit.go
@@ -61,6 +61,10 @@ func _edit(filepaths []string) error {
|
||||
original, err := pttodo.NewRootFromFile(func() string {
|
||||
for _, f := range filepaths {
|
||||
if path.Base(f) == path.Base(editedFile) {
|
||||
rootF := path.Join(path.Dir(f), "."+path.Base(f))
|
||||
if _, err := os.Stat(rootF); err == nil {
|
||||
f = rootF
|
||||
}
|
||||
return f
|
||||
}
|
||||
}
|
||||
@@ -102,8 +106,15 @@ func _edit(filepaths []string) error {
|
||||
|
||||
dir := ""
|
||||
for _, f := range filepaths {
|
||||
rootF := path.Join(path.Dir(f), "."+path.Base(f))
|
||||
if edited, ok := edits[path.Base(f)]; ok {
|
||||
if err := rename(edited, f); err != nil {
|
||||
if todos, err := pttodo.NewRootFromFile(edited); err != nil {
|
||||
return err
|
||||
} else if b, err := yaml.Marshal(todos.Todo); err != nil {
|
||||
return err
|
||||
} else if err := rename(edited, rootF); err != nil {
|
||||
return err
|
||||
} else if err := os.WriteFile(f, b, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
delete(edits, path.Base(f))
|
||||
|
||||
Reference in New Issue
Block a user