Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a54ccae4c2 | ||
|
|
a27d5c38d7 | ||
|
|
cb4886992a | ||
|
|
15c5f03ccf | ||
|
|
b82f11c248 | ||
|
|
3c9b34202b | ||
|
|
967a02c90a |
@@ -57,17 +57,25 @@ func edit(dry bool, filepath string) error {
|
||||
g.Close()
|
||||
}
|
||||
f.Close()
|
||||
tempFile = f.Name()
|
||||
return nil
|
||||
tempFile = f.Name() + ".yaml"
|
||||
return os.Rename(f.Name(), tempFile)
|
||||
}
|
||||
vi := func() error {
|
||||
vibin, err := exec.LookPath("vi")
|
||||
bin := "vim"
|
||||
if editor := os.Getenv("EDITOR"); editor != "" {
|
||||
bin = editor
|
||||
}
|
||||
editorbin, err := exec.LookPath(bin)
|
||||
if err != nil {
|
||||
editorbin, err = exec.LookPath("vi")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
args := []string{editorbin, tempFile}
|
||||
cpid, err := syscall.ForkExec(
|
||||
vibin,
|
||||
[]string{vibin, tempFile},
|
||||
editorbin,
|
||||
args,
|
||||
&syscall.ProcAttr{
|
||||
Dir: "",
|
||||
Env: os.Environ(),
|
||||
@@ -92,7 +100,10 @@ func edit(dry bool, filepath string) error {
|
||||
return nil
|
||||
}
|
||||
verify := func() error {
|
||||
return dump(true, io.Discard, tempFile)
|
||||
if err := dump(true, io.Discard, tempFile); err != nil {
|
||||
return fmt.Errorf("failed to verify %s: %v", tempFile, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
save := func() error {
|
||||
if dry {
|
||||
@@ -104,12 +115,12 @@ func edit(dry bool, filepath string) error {
|
||||
|
||||
for _, foo := range []func() error{cp, vi, verify, save} {
|
||||
if err := foo(); err != nil {
|
||||
if tempFile != "" && !dry {
|
||||
os.Remove(tempFile)
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !dry {
|
||||
os.Remove(tempFile)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
23
pttodo/ts.go
23
pttodo/ts.go
@@ -2,7 +2,10 @@ package pttodo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type TS int64
|
||||
@@ -23,9 +26,25 @@ func (ts TS) MarshalYAML() (interface{}, error) {
|
||||
if ts == 0 {
|
||||
ts = TS(time.Now().Unix())
|
||||
}
|
||||
return int64(ts), nil
|
||||
t := time.Unix(int64(ts), 0)
|
||||
return t.Format(time.UnixDate), nil
|
||||
}
|
||||
|
||||
func (ts *TS) UnmarshalJSON(b []byte) error {
|
||||
return json.Unmarshal(b, (*int64)(ts))
|
||||
return yaml.Unmarshal(b, ts)
|
||||
}
|
||||
|
||||
func (ts *TS) UnmarshalYAML(unmarshaller func(interface{}) error) error {
|
||||
var n int64
|
||||
if err := unmarshaller(&n); err == nil {
|
||||
*ts = TS(n)
|
||||
return nil
|
||||
}
|
||||
var s string
|
||||
if err := unmarshaller(&s); err == nil {
|
||||
t, err := time.Parse(time.UnixDate, s)
|
||||
*ts = TS(t.Unix())
|
||||
return err
|
||||
}
|
||||
return errors.New("illegal TS")
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
@@ -14,7 +13,7 @@ func TestTSMarshalYaml(t *testing.T) {
|
||||
var ts TS
|
||||
if b, err := yaml.Marshal(TS(5)); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if s := string(b); strings.TrimSpace(s) != `5` {
|
||||
} else if s := string(b); !strings.HasSuffix(strings.TrimSpace(s), ` 1969`) {
|
||||
t.Fatal(s)
|
||||
} else if err := yaml.Unmarshal(b, &ts); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -37,7 +36,7 @@ func TestTSMarshalYaml(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestJSONTS(t *testing.T) {
|
||||
ts := TS(time.Now().Unix())
|
||||
ts := TS(1234567890)
|
||||
js, err := json.Marshal(ts)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -48,7 +47,7 @@ func TestJSONTS(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ts != ts2 {
|
||||
t.Fatal(ts2)
|
||||
t.Fatalf("want: %v, got: %v", ts, ts2)
|
||||
}
|
||||
|
||||
if err := json.Unmarshal([]byte(`123`), &ts2); err != nil {
|
||||
|
||||
0
sample.yaml → testdata/sample.yaml
vendored
0
sample.yaml → testdata/sample.yaml
vendored
31
todo.yaml
31
todo.yaml
@@ -1,10 +1,12 @@
|
||||
todo:
|
||||
- todo: when to run scheduled modifier? like, syncthing could have conflicts if I modify only file on remote
|
||||
- todo: when to run scheduled modifier? like, syncthing could have conflicts if I
|
||||
modify only file on remote
|
||||
ts: Fri Dec 31 22:33:12 EST 2021
|
||||
details: |
|
||||
- if it's a web ui hook or somethin, then it'd only have file conflict if I modify without waiting
|
||||
- but thats a step back from current todo solution
|
||||
|
||||
- todo: ez edit on many platforms, even offline and mobile
|
||||
ts: Fri Dec 31 22:33:12 EST 2021
|
||||
details: |
|
||||
mobile view + complete method
|
||||
collab editing of file prob resolves mobile and other stuff...
|
||||
@@ -12,22 +14,35 @@ todo:
|
||||
web server access to ops
|
||||
is a web ui for mobile best solution?
|
||||
let git be smart-ish and keep latest? would provide versioning OOTB without touching raw
|
||||
|
||||
scheduled: []
|
||||
done:
|
||||
- todo: crontab -e style editing to ensure good syntax
|
||||
- ts to human readable
|
||||
- here is my really here is my really here is my really here is my really here is
|
||||
my really here is my really here is my really here is my really here is my really
|
||||
here is my really here is my really here is my really here is my really here is
|
||||
my really here is my really long string
|
||||
- vim doesnt source vimrc, so stuff like tab width and tab characters, also syntax
|
||||
highlight :(
|
||||
- crontab -e style editing to ensure good syntax
|
||||
- todo: YAML based todo
|
||||
details:
|
||||
because goddamnit a year of this shit
|
||||
isn't significant on disk or in RAM for vim
|
||||
ts: Fri Dec 31 22:33:12 EST 2021
|
||||
details: because goddamnit a year of this shit isn't significant on disk or in RAM
|
||||
for vim
|
||||
- todo: yaml based todo for plaintext
|
||||
ts: Fri Dec 31 22:33:12 EST 2021
|
||||
details: a year isnt even a mb
|
||||
- ez edit, start on many platforms
|
||||
- defer
|
||||
- schedule
|
||||
- looping
|
||||
- details
|
||||
- todo: let UI be UI for whatever platform
|
||||
- let UI be UI for whatever platform
|
||||
- tags
|
||||
- todo: sub tasks
|
||||
ts: Fri Dec 31 22:33:12 EST 2021
|
||||
subtasks:
|
||||
- a
|
||||
- todo: crap losing on a bad edit hurts
|
||||
ts: Fri Dec 31 22:37:58 EST 2021
|
||||
details: |
|
||||
?
|
||||
|
||||
Reference in New Issue
Block a user