78 Commits

Author SHA1 Message Date
Bel LaPointe
7a20f3fdda split config.go 2023-11-06 10:37:34 -07:00
Bel LaPointe
7618d5665b split dump.go from main.go in cli 2023-11-06 10:35:01 -07:00
Bel LaPointe
a5869aaa89 split cli.go into add.go, edit.go too 2023-11-06 10:33:32 -07:00
Bel LaPointe
b1df4b62af drop some args 2023-11-06 10:28:36 -07:00
bel
87c937b6f1 oop 2023-10-15 10:40:13 -06:00
bel
ed474b8c3a default file path if not empty 2023-10-15 10:39:58 -06:00
bel
46e62dc485 fix nil ptr on no previous file 2023-10-15 10:39:01 -06:00
Bel LaPointe
236355b69d skip hidden files 2023-08-16 06:54:21 -06:00
Bel LaPointe
6bb6c847aa nil ptr 2023-07-16 19:47:11 -06:00
Bel LaPointe
6bad1e1365 on write conflict during vim, save as filename.uuid..fileExtension 2023-07-02 10:22:04 -06:00
Bel LaPointe
d105df15e9 support -add-tags x,y,z 2023-04-24 15:02:13 -06:00
Bel LaPointe
afc7d6001a fix 2023-04-10 10:45:16 -06:00
Bel LaPointe
242f9ee1b4 gr 2023-04-10 10:44:41 -06:00
Bel LaPointe
5a30481ff1 partial go mod 2023-04-10 10:42:11 -06:00
Bel LaPointe
438c0ade59 gitignore 2022-09-10 11:25:23 -06:00
Bel LaPointe
e5b3fd3195 no prior file exists ok 2022-09-10 11:24:41 -06:00
Bel LaPointe
49893c7ffe on scheduled task done, in addition to requeue, add to done 2022-09-10 11:13:18 -06:00
Bel LaPointe
39d222b133 quick add via cli -add, -add-schedule 2022-04-07 12:48:17 -06:00
Bel LaPointe
461e88ee17 root moves fixed future schedules to shceduled on automove 2022-03-24 14:43:45 -06:00
Bel LaPointe
916ad212f4 revert to clean todo 2022-03-24 09:26:44 -06:00
Bel LaPointe
bd5028ff8d revert automove for crons 2022-03-24 09:25:34 -06:00
Bel LaPointe
21ccb7ff4c 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
1b1ed01937 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
5a1936721d add todo.ID() 2022-03-23 09:42:21 -06:00
Bel LaPointe
77fb27dc09 ready for find deleted 2022-03-23 08:06:57 -06:00
Bel LaPointe
2eda765ad9 if item in todo is scheduled for later, then move it 2022-03-23 08:04:35 -06:00
Bel LaPointe
a8fbc13e7c new edit ready for shuffles 2022-03-23 07:49:54 -06:00
Bel LaPointe
d8e732087a getconfig in pttodo-cli 2022-03-23 07:27:49 -06:00
Bel LaPointe
7d98e6f0fc update tests for mst 2022-03-23 07:13:55 -06:00
bel
82a615919c wip 2022-02-20 17:11:16 -07:00
Bel LaPointe
50913b8913 change default file path from stdin 2022-01-10 09:44:30 -05:00
Bel LaPointe
42d532ee61 update todo 2022-01-09 10:27:30 -05:00
Bel LaPointe
24316fe690 accept THH on ezdate 2022-01-09 10:24:40 -05:00
Bel LaPointe
8058304219 dont log noops 2022-01-09 10:22:23 -05:00
Bel LaPointe
7f24b3f337 do not save if no effective changes for edit, dump 2022-01-09 10:18:08 -05:00
Bel LaPointe
fc12e0550d add root.equals and todo.equals 2022-01-09 10:17:44 -05:00
Bel LaPointe
05f5244cd1 root.yaml prio, otherwise sort -f results 2022-01-08 23:44:30 -05:00
Bel LaPointe
c559c8eba6 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
dd7ac8d786 parseinlocation for non utc crud 2022-01-06 21:28:44 -05:00
Bel LaPointe
ccdd2615c4 instead of trashing editing file in cli, write err msg and re-edit 2022-01-04 12:37:35 -05:00
Bel LaPointe
0241f2d76c err msg 2022-01-04 12:33:39 -05:00
Bel LaPointe
fa812a16ee fix checking hastags and nothas tags 2022-01-04 08:56:19 -05:00
Bel LaPointe
cf3b233a11 add anti tag search 2022-01-04 07:01:35 -05:00
Bel LaPointe
64868bdc0b create script to scrape list of lists and scrape aech into a yaml 2022-01-03 16:36:59 -05:00
Bel LaPointe
1b1724bea7 update todo with no more ts in todo section 2022-01-02 20:45:17 -05:00
Bel LaPointe
f4968d1d1b update todo 2022-01-02 20:44:23 -05:00
Bel LaPointe
6203ced79b root does not marshal TSs on todos, always on schedules, dones. Test. 2022-01-02 20:44:04 -05:00
Bel LaPointe
4d171d10d0 only write TS on a todo if writeTS is set 2022-01-02 20:37:40 -05:00
Bel LaPointe
8ad2ca9345 new todo 2022-01-02 20:32:16 -05:00
Bel LaPointe
bc0bb05fb6 update todo 2022-01-02 20:31:09 -05:00
Bel LaPointe
22dc04341c update todo.yaml 2022-01-02 20:17:32 -05:00
Bel LaPointe
bf10c00708 add cli -g to merge in a file 2022-01-02 20:07:52 -05:00
Bel LaPointe
cd5ce0f0df add root MergeIn 2022-01-01 17:43:20 -05:00
Bel LaPointe
eb41f065a5 todo 2022-01-01 17:33:59 -05:00
Bel LaPointe
96bfb96ee3 consts for what to print, default to just the todos 2022-01-01 17:30:40 -05:00
Bel LaPointe
770f2719d2 ezdate for yyyy-mm-dd for schedule 2022-01-01 17:21:38 -05:00
Bel LaPointe
3554bf8ba4 rm test code 2022-01-01 17:14:03 -05:00
Bel LaPointe
b4aa4ad310 ts shouldnt yield zero ever, yield now if so 2022-01-01 17:13:50 -05:00
Bel LaPointe
0dddf26265 fix getting ts for completed tasks 2022-01-01 17:04:21 -05:00
Bel LaPointe
5afdeed3b5 todo 2021-12-31 23:27:21 -05:00
Bel LaPointe
af0f094a65 support tag, simple case insensitve search when recursing 2021-12-31 23:20:27 -05:00
Bel LaPointe
031db8788b tag saerch on todo 2021-12-31 23:14:31 -05:00
Bel LaPointe
b8efdbfa52 when writing output file, dont recurse 2021-12-31 23:03:08 -05:00
Bel LaPointe
a54ccae4c2 update todo 2021-12-31 23:00:16 -05:00
Bel LaPointe
a27d5c38d7 times are now unix dates over ints 2021-12-31 22:59:13 -05:00
Bel LaPointe
cb4886992a remove unused stub 2021-12-31 22:49:51 -05:00
Bel LaPointe
15c5f03ccf fix syntax highlight by using tempfile.yaml over tempfile 2021-12-31 22:46:49 -05:00
Bel LaPointe
b82f11c248 dont try to find vimrc 2021-12-31 22:45:29 -05:00
Bel LaPointe
3c9b34202b use $EDITOR, default to vim, use $HOME/.vimrc if exists 2021-12-31 22:44:33 -05:00
Bel LaPointe
967a02c90a updated todo because i oofed 2021-12-31 22:37:47 -05:00
Bel LaPointe
3ed7d8cd9e update install for gomo 2021-12-31 22:32:47 -05:00
Bel LaPointe
492e0af993 if optional positional arg is todo/scheduled/done, then resolve first level 2021-12-31 22:32:07 -05:00
Bel LaPointe
10b95672e3 up install script for location 2021-12-31 22:28:12 -05:00
Bel LaPointe
183f39bd2a set ts to currenttime if should display 2021-12-31 22:27:48 -05:00
Bel LaPointe
24154df995 cli has dry mode and install script 2021-12-31 22:27:33 -05:00
Bel LaPointe
f7dac79233 pttodo-cli default file via env 2021-12-31 22:07:16 -05:00
Bel LaPointe
8c45d4a7df pttodo-cli works even if file does not initially exist 2021-12-31 22:05:47 -05:00
Bel LaPointe
1e3f24b4d5 rename gomod, root project 2021-12-31 21:58:02 -05:00
20 changed files with 153 additions and 89 deletions

1
.gitignore vendored
View File

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

View File

@@ -1,40 +0,0 @@
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
}

46
cmd/pttodo-cli/add.go Normal file
View File

@@ -0,0 +1,46 @@
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

@@ -12,4 +12,4 @@ require (
github.com/robfig/cron/v3 v3.0.1 // indirect 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,6 +2,7 @@ package main
import ( import (
"bytes" "bytes"
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@@ -29,7 +30,7 @@ func main() {
func _main() error { func _main() error {
config := getConfig() config := getConfig()
if err := add(&config); err != nil { if err := add(config); err != nil {
return err return err
} }
if err := edit(config); err != nil { if err := edit(config); err != nil {
@@ -38,6 +39,31 @@ func _main() error {
return dump(config) 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 { func merge(filepath string, mergeTargetFilePath string) error {
baseReader, err := filePathReader(filepath) baseReader, err := filePathReader(filepath)
if err != nil { if err != nil {
@@ -67,6 +93,9 @@ func merge(filepath string, mergeTargetFilePath string) error {
base.MergeIn(merging) base.MergeIn(merging)
if err := verifyRoot(base); err != nil {
return err
}
tmppath, err := marshalRootToTempFile(base) tmppath, err := marshalRootToTempFile(base)
if err != nil { if err != nil {
return err return err

View File

@@ -0,0 +1,21 @@
#! /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

@@ -0,0 +1,55 @@
#! /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,36 +1,11 @@
package pttodo package pttodo
import (
"os"
yaml "gopkg.in/yaml.v2"
)
type Root struct { type Root struct {
Todo []Todo Todo []Todo
Scheduled []Todo Scheduled []Todo
Done []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 { func (root Root) Equals(other Root) bool {
for i, slice := range [][2][]Todo{ for i, slice := range [][2][]Todo{
[2][]Todo{root.Todo, other.Todo}, [2][]Todo{root.Todo, other.Todo},

View File

@@ -4,10 +4,7 @@ import (
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"hash/crc32" "hash/crc32"
"os"
"time" "time"
yaml "gopkg.in/yaml.v2"
) )
type Todo struct { type Todo struct {
@@ -20,24 +17,6 @@ type Todo struct {
writeTS bool 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 { func (todo Todo) ID() string {
hash := crc32.NewIEEE() hash := crc32.NewIEEE()
fmt.Fprintf(hash, "%d:%s", 0, todo.Todo) fmt.Fprintf(hash, "%d:%s", 0, todo.Todo)