85 Commits

Author SHA1 Message Date
Bel LaPointe
23ef7f13ee gitignore bin 2023-11-06 12:15:29 -07:00
Bel LaPointe
02dab4b726 move pttodo-cli up from /cmd/ 2023-11-06 12:15:12 -07:00
Bel LaPointe
cdd1be46a8 drop unused 2023-11-06 12:14:37 -07:00
Bel LaPointe
760c822323 add pttodo.NewRootFromFile, pttodo.NewTodosFromFile 2023-11-06 12:14:27 -07:00
Bel LaPointe
4e69646e88 drop dumb verifies 2023-11-06 12:14:16 -07:00
Bel LaPointe
9aee322c4e drop old 2023-11-06 12:11:44 -07:00
Bel LaPointe
887875f6d8 add creates a .todo.* file 2023-11-06 12:03:03 -07:00
Bel LaPointe
d2f986d8b6 split config.go 2023-11-06 10:37:34 -07:00
Bel LaPointe
58aa05c155 split dump.go from main.go in cli 2023-11-06 10:35:01 -07:00
Bel LaPointe
97aff0f0b8 split cli.go into add.go, edit.go too 2023-11-06 10:33:32 -07:00
Bel LaPointe
eb20706d12 drop some args 2023-11-06 10:28:36 -07:00
bel
a800227c6f oop 2023-10-15 10:40:13 -06:00
bel
2c7563c1ab default file path if not empty 2023-10-15 10:39:58 -06:00
bel
a8a135bb2f fix nil ptr on no previous file 2023-10-15 10:39:01 -06:00
Bel LaPointe
c1c625afc0 skip hidden files 2023-08-16 06:54:21 -06:00
Bel LaPointe
0b790e3468 nil ptr 2023-07-16 19:47:11 -06:00
Bel LaPointe
7175d777cb on write conflict during vim, save as filename.uuid..fileExtension 2023-07-02 10:22:04 -06:00
Bel LaPointe
debe28dbbc support -add-tags x,y,z 2023-04-24 15:02:13 -06:00
Bel LaPointe
c1426566a0 fix 2023-04-10 10:45:16 -06:00
Bel LaPointe
6f79f7da5e gr 2023-04-10 10:44:41 -06:00
Bel LaPointe
284d7c06bd partial go mod 2023-04-10 10:42:11 -06:00
Bel LaPointe
be702b1d74 gitignore 2022-09-10 11:25:23 -06:00
Bel LaPointe
de62d99340 no prior file exists ok 2022-09-10 11:24:41 -06:00
Bel LaPointe
bca9259caa on scheduled task done, in addition to requeue, add to done 2022-09-10 11:13:18 -06:00
Bel LaPointe
dccf5c4028 quick add via cli -add, -add-schedule 2022-04-07 12:48:17 -06:00
Bel LaPointe
55e174e3b1 root moves fixed future schedules to shceduled on automove 2022-03-24 14:43:45 -06:00
Bel LaPointe
d7dab75f48 revert to clean todo 2022-03-24 09:26:44 -06:00
Bel LaPointe
3426deae4d revert automove for crons 2022-03-24 09:25:34 -06:00
Bel LaPointe
7fe4686c05 always write ts, when a todo with schedule deleted, conditionally go back to schedule for loopers 2022-03-24 09:18:19 -06:00
Bel LaPointe
eb57593665 cli on delete todo, write in Done identified by entire struct so dupes wouldnt but thats ok 2022-03-23 09:46:16 -06:00
Bel LaPointe
814ae3ab23 add todo.ID() 2022-03-23 09:42:21 -06:00
Bel LaPointe
939793bd3f ready for find deleted 2022-03-23 08:06:57 -06:00
Bel LaPointe
1d26cf125f if item in todo is scheduled for later, then move it 2022-03-23 08:04:35 -06:00
Bel LaPointe
e20ce478d5 new edit ready for shuffles 2022-03-23 07:49:54 -06:00
Bel LaPointe
0bd6347a93 getconfig in pttodo-cli 2022-03-23 07:27:49 -06:00
Bel LaPointe
20770ff5e6 update tests for mst 2022-03-23 07:13:55 -06:00
bel
65178b8bdf wip 2022-02-20 17:11:16 -07:00
Bel LaPointe
4066d4aeb5 change default file path from stdin 2022-01-10 09:44:30 -05:00
Bel LaPointe
7f611e67bc update todo 2022-01-09 10:27:30 -05:00
Bel LaPointe
71c03f3ef5 accept THH on ezdate 2022-01-09 10:24:40 -05:00
Bel LaPointe
4b8d82c2a0 dont log noops 2022-01-09 10:22:23 -05:00
Bel LaPointe
850ff92d98 do not save if no effective changes for edit, dump 2022-01-09 10:18:08 -05:00
Bel LaPointe
c2d1381607 add root.equals and todo.equals 2022-01-09 10:17:44 -05:00
Bel LaPointe
33ca7c60e1 root.yaml prio, otherwise sort -f results 2022-01-08 23:44:30 -05:00
Bel LaPointe
cde6ea6cb6 if cli -f is a dir, then edit each file+clean each file+keep each as individual file 2022-01-08 23:42:05 -05:00
Bel LaPointe
6d3f423845 parseinlocation for non utc crud 2022-01-06 21:28:44 -05:00
Bel LaPointe
fe1bd22987 instead of trashing editing file in cli, write err msg and re-edit 2022-01-04 12:37:35 -05:00
Bel LaPointe
6f9589b100 err msg 2022-01-04 12:33:39 -05:00
Bel LaPointe
a0c0cb7053 fix checking hastags and nothas tags 2022-01-04 08:56:19 -05:00
Bel LaPointe
4a22b964db add anti tag search 2022-01-04 07:01:35 -05:00
Bel LaPointe
2caf2ae352 create script to scrape list of lists and scrape aech into a yaml 2022-01-03 16:36:59 -05:00
Bel LaPointe
455a7d52d5 update todo with no more ts in todo section 2022-01-02 20:45:17 -05:00
Bel LaPointe
1a9221f7c7 update todo 2022-01-02 20:44:23 -05:00
Bel LaPointe
6178e6ff93 root does not marshal TSs on todos, always on schedules, dones. Test. 2022-01-02 20:44:04 -05:00
Bel LaPointe
fdb24fcc60 only write TS on a todo if writeTS is set 2022-01-02 20:37:40 -05:00
Bel LaPointe
8002b5e75c new todo 2022-01-02 20:32:16 -05:00
Bel LaPointe
3dd8cd1e03 update todo 2022-01-02 20:31:09 -05:00
Bel LaPointe
c6ab36806d update todo.yaml 2022-01-02 20:17:32 -05:00
Bel LaPointe
bf997c1814 add cli -g to merge in a file 2022-01-02 20:07:52 -05:00
Bel LaPointe
69eb868db6 add root MergeIn 2022-01-01 17:43:20 -05:00
Bel LaPointe
0c80162394 todo 2022-01-01 17:33:59 -05:00
Bel LaPointe
c634fdd4d4 consts for what to print, default to just the todos 2022-01-01 17:30:40 -05:00
Bel LaPointe
92d76443bc ezdate for yyyy-mm-dd for schedule 2022-01-01 17:21:38 -05:00
Bel LaPointe
a51d5e6960 rm test code 2022-01-01 17:14:03 -05:00
Bel LaPointe
7fc594d5c2 ts shouldnt yield zero ever, yield now if so 2022-01-01 17:13:50 -05:00
Bel LaPointe
2d8cfa6397 fix getting ts for completed tasks 2022-01-01 17:04:21 -05:00
Bel LaPointe
f01dc04277 todo 2021-12-31 23:27:21 -05:00
Bel LaPointe
249ee84688 support tag, simple case insensitve search when recursing 2021-12-31 23:20:27 -05:00
Bel LaPointe
4111d1f490 tag saerch on todo 2021-12-31 23:14:31 -05:00
Bel LaPointe
5b6f62983b when writing output file, dont recurse 2021-12-31 23:03:08 -05:00
Bel LaPointe
1056f5d29e update todo 2021-12-31 23:00:16 -05:00
Bel LaPointe
7886723fe3 times are now unix dates over ints 2021-12-31 22:59:13 -05:00
Bel LaPointe
ff77af9ed4 remove unused stub 2021-12-31 22:49:51 -05:00
Bel LaPointe
3bd1c6462d fix syntax highlight by using tempfile.yaml over tempfile 2021-12-31 22:46:49 -05:00
Bel LaPointe
3bcabde553 dont try to find vimrc 2021-12-31 22:45:29 -05:00
Bel LaPointe
604cd610a1 use $EDITOR, default to vim, use $HOME/.vimrc if exists 2021-12-31 22:44:33 -05:00
Bel LaPointe
9d35347b0c updated todo because i oofed 2021-12-31 22:37:47 -05:00
Bel LaPointe
1a8c687260 update install for gomo 2021-12-31 22:32:47 -05:00
Bel LaPointe
3246900db0 if optional positional arg is todo/scheduled/done, then resolve first level 2021-12-31 22:32:07 -05:00
Bel LaPointe
79cc171af5 up install script for location 2021-12-31 22:28:12 -05:00
Bel LaPointe
a75d898487 set ts to currenttime if should display 2021-12-31 22:27:48 -05:00
Bel LaPointe
f63f152b0e cli has dry mode and install script 2021-12-31 22:27:33 -05:00
Bel LaPointe
76a0231511 pttodo-cli default file via env 2021-12-31 22:07:16 -05:00
Bel LaPointe
7f37feea77 pttodo-cli works even if file does not initially exist 2021-12-31 22:05:47 -05:00
Bel LaPointe
b84f8b59c9 rename gomod, root project 2021-12-31 21:58:02 -05:00
20 changed files with 89 additions and 153 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ cmd/cmd
cmd/cli
cmd/pttodo/pttodo
cmd/pttodo-cli/pttodo-cli
cmd/pttodo-cli

40
cmd/add.go Normal file
View File

@@ -0,0 +1,40 @@
package main
import (
"io/ioutil"
"os"
"github.com/google/uuid"
"gogs.inhome.blapointe.com/bel/pttodo/pttodo"
"gopkg.in/yaml.v2"
)
func add(config *config) error {
if config.add == "" {
return nil
}
v := pttodo.Todo{
Todo: config.add,
Schedule: pttodo.Schedule(config.addSchedule),
Tags: config.addTags,
}
newTarget, err := _add(config.targets, v)
if err != nil {
return err
}
config.targets = append(config.targets, newTarget)
return nil
}
func _add(filepaths []string, todo pttodo.Todo) (string, error) {
target := filepaths[0] + ".todo." + uuid.New().String()
c, err := yaml.Marshal([]pttodo.Todo{todo})
if err != nil {
return "", err
} else if err := ioutil.WriteFile(target, c, os.ModePerm); err != nil {
return "", err
}
return target, nil
}

View File

@@ -12,4 +12,4 @@ require (
github.com/robfig/cron/v3 v3.0.1 // indirect
)
replace gogs.inhome.blapointe.com/bel/pttodo => ../..
replace gogs.inhome.blapointe.com/bel/pttodo => ./..

View File

@@ -2,7 +2,6 @@ package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
@@ -30,7 +29,7 @@ func main() {
func _main() error {
config := getConfig()
if err := add(config); err != nil {
if err := add(&config); err != nil {
return err
}
if err := edit(config); err != nil {
@@ -39,31 +38,6 @@ func _main() error {
return dump(config)
}
func verifyRoot(root pttodo.Root) error {
f, err := ioutil.TempFile(os.TempDir(), "tmp")
if err != nil {
return err
}
f.Close()
tempFile := f.Name()
b, err := yaml.Marshal(root)
if err != nil {
return err
}
if err := ioutil.WriteFile(tempFile, b, os.ModePerm); err != nil {
return err
}
defer os.Remove(tempFile)
return verifyFile(tempFile)
}
func verifyFile(path string) error {
if err := _dump(io.Discard, []string{path}, nil, "", DUMP_ALL); err != nil {
return fmt.Errorf("failed verifying file %s: %w", path, err)
}
return nil
}
func merge(filepath string, mergeTargetFilePath string) error {
baseReader, err := filePathReader(filepath)
if err != nil {
@@ -93,9 +67,6 @@ func merge(filepath string, mergeTargetFilePath string) error {
base.MergeIn(merging)
if err := verifyRoot(base); err != nil {
return err
}
tmppath, err := marshalRootToTempFile(base)
if err != nil {
return err

View File

@@ -1,46 +0,0 @@
package main
import (
"io/ioutil"
"os"
"gogs.inhome.blapointe.com/bel/pttodo/pttodo"
"gopkg.in/yaml.v2"
)
func add(config config) error {
if config.add == "" {
return nil
}
v := pttodo.Todo{
Todo: config.add,
Schedule: pttodo.Schedule(config.addSchedule),
Tags: config.addTags,
}
return _add(config.targets, v)
}
func _add(filepaths []string, todo pttodo.Todo) error {
target := filepaths[0]
var original pttodo.Root
r, err := filePathReader(target)
if err != nil {
return err
}
if err := yaml.NewDecoder(r).Decode(&original); err != nil {
return err
}
original.Todo = append([]pttodo.Todo{todo}, original.Todo...)
original.AutoMove()
c, err := yaml.Marshal(original)
if err != nil {
return err
} else if err := ioutil.WriteFile(target, c, os.ModePerm); err != nil {
return err
}
return nil
}

View File

@@ -1,21 +0,0 @@
#! /bin/bash
main() {
cd "$(dirname "$BASH_SOURCE")"
source ./from_todo_server_to_pttodo.sh
type from_todo_server_to_pttodo_main
list_lists | jq .list[] | jq -c . | while read -r line; do
local name="$(echo "$line" | jq -r .name | sed 's/^Today$/todo/g' | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g')"
local id="$(echo "$line" | jq -r .id)"
echo $name, $id
TODO_SERVER_LIST="$id" from_todo_server_to_pttodo_main > ./$name.yaml
done
}
list_lists() {
todo_server_curl "$TODO_SERVER_URL/ajax.php?loadLists=&rnd=0.9900282499544026"
}
if [ "$0" == "$BASH_SOURCE" ]; then
main "$@"
fi

View File

@@ -1,55 +0,0 @@
#! /bin/bash
export TODO_SERVER_URL="${TODO_SERVER_URL:-"https://todo-server.remote.blapointe.com"}"
export TODO_SERVER_HEADERS="${TODO_SERVER_HEADERS:-"Cookie: BOAuthZ=$TODO_SERVER_BOAUTHZ"}"
export TODO_SERVER_LIST="${TODO_SERVER_LIST:-"2548023766"}"
main() {
from_todo_server_to_pttodo_main "$@"
}
from_todo_server_to_pttodo_main() {
set -e
set -o pipefail
local tasks_in_todo="$(fetch_tasks_in_list | format_tasks_in_list)"
local schedule_tasks_in_flight="$(COMPL=1 LOOPING=1 fetch_tasks_in_list | format_tasks_in_list)"
echo "{\"todo\": $tasks_in_todo, \"scheduled\": $schedule_tasks_in_flight, \"done\": []}" | yq -P eval -
}
format_tasks_in_list() {
jq -c .list[] | while read -r line; do
echo "$line" \
| jq '{
todo: .title,
details:.note,
ts: (if .compl == 1 then (.dateCompleted | strptime("%d %b %Y %I:%M %p") | mktime) else .dateEditedInt end),
subtasks: [],
tags: .tags,
schedule: (if (.cron != "") then (.cron) else (.loop) end)
}' \
| jq -c .
done | jq -sc | yq -P eval - | grep -v -E ' (""|\[]|0s)$' | yq -j eval - | jq -c .
}
fetch_tasks_in_list() {
todo_server_curl "$TODO_SERVER_URL/ajax.php?loadTasks=&list=$TODO_SERVER_LIST&compl=${COMPL:-0}&looping=${LOOPING:-0}"
}
todo_server_curl() {
local csv_headers="$TODO_SERVER_HEADERS"
local headers=()
while [ "$csv_headers" != "" ]; do
header="${csv_headers%%,*}"
headers+=("-H" "${header%%:*}: ${header#*:}")
if echo "$csv_headers" | grep -q ,; then
csv_headers="${csv_headers#*,}"
else
csv_headers=""
fi
done
curl -sS "${headers[@]}" "$@"
}
if [ "$0" == "$BASH_SOURCE" ]; then
main "$@"
fi

View File

@@ -1,11 +1,36 @@
package pttodo
import (
"os"
yaml "gopkg.in/yaml.v2"
)
type Root struct {
Todo []Todo
Scheduled []Todo
Done []Todo
}
func NewRootFromFile(p string) (Root, error) {
f, err := os.Open(p)
if os.IsNotExist(err) {
return Root{}, nil
}
if err != nil {
return Root{}, err
}
defer f.Close()
var result Root
if err := yaml.NewDecoder(f).Decode(&result); err != nil {
return Root{}, err
}
result.AutoMove()
return result, nil
}
func (root Root) Equals(other Root) bool {
for i, slice := range [][2][]Todo{
[2][]Todo{root.Todo, other.Todo},

View File

@@ -4,7 +4,10 @@ import (
"encoding/base64"
"fmt"
"hash/crc32"
"os"
"time"
yaml "gopkg.in/yaml.v2"
)
type Todo struct {
@@ -17,6 +20,24 @@ type Todo struct {
writeTS bool
}
func NewTodosFromFile(p string) ([]Todo, error) {
f, err := os.Open(p)
if os.IsNotExist(err) {
return nil, nil
}
if err != nil {
return nil, err
}
defer f.Close()
var result []Todo
if err := yaml.NewDecoder(f).Decode(&result); err != nil {
return nil, err
}
return result, nil
}
func (todo Todo) ID() string {
hash := crc32.NewIEEE()
fmt.Fprintf(hash, "%d:%s", 0, todo.Todo)