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()
|
g.Close()
|
||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
tempFile = f.Name()
|
tempFile = f.Name() + ".yaml"
|
||||||
return nil
|
return os.Rename(f.Name(), tempFile)
|
||||||
}
|
}
|
||||||
vi := func() error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
args := []string{editorbin, tempFile}
|
||||||
cpid, err := syscall.ForkExec(
|
cpid, err := syscall.ForkExec(
|
||||||
vibin,
|
editorbin,
|
||||||
[]string{vibin, tempFile},
|
args,
|
||||||
&syscall.ProcAttr{
|
&syscall.ProcAttr{
|
||||||
Dir: "",
|
Dir: "",
|
||||||
Env: os.Environ(),
|
Env: os.Environ(),
|
||||||
@@ -92,7 +100,10 @@ func edit(dry bool, filepath string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
verify := func() error {
|
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 {
|
save := func() error {
|
||||||
if dry {
|
if dry {
|
||||||
@@ -104,12 +115,12 @@ func edit(dry bool, filepath string) error {
|
|||||||
|
|
||||||
for _, foo := range []func() error{cp, vi, verify, save} {
|
for _, foo := range []func() error{cp, vi, verify, save} {
|
||||||
if err := foo(); err != nil {
|
if err := foo(); err != nil {
|
||||||
if tempFile != "" && !dry {
|
|
||||||
os.Remove(tempFile)
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !dry {
|
||||||
|
os.Remove(tempFile)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
23
pttodo/ts.go
23
pttodo/ts.go
@@ -2,7 +2,10 @@ package pttodo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TS int64
|
type TS int64
|
||||||
@@ -23,9 +26,25 @@ func (ts TS) MarshalYAML() (interface{}, error) {
|
|||||||
if ts == 0 {
|
if ts == 0 {
|
||||||
ts = TS(time.Now().Unix())
|
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 {
|
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"
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
@@ -14,7 +13,7 @@ func TestTSMarshalYaml(t *testing.T) {
|
|||||||
var ts TS
|
var ts TS
|
||||||
if b, err := yaml.Marshal(TS(5)); err != nil {
|
if b, err := yaml.Marshal(TS(5)); err != nil {
|
||||||
t.Fatal(err)
|
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)
|
t.Fatal(s)
|
||||||
} else if err := yaml.Unmarshal(b, &ts); err != nil {
|
} else if err := yaml.Unmarshal(b, &ts); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -37,7 +36,7 @@ func TestTSMarshalYaml(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestJSONTS(t *testing.T) {
|
func TestJSONTS(t *testing.T) {
|
||||||
ts := TS(time.Now().Unix())
|
ts := TS(1234567890)
|
||||||
js, err := json.Marshal(ts)
|
js, err := json.Marshal(ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -48,7 +47,7 @@ func TestJSONTS(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if ts != ts2 {
|
if ts != ts2 {
|
||||||
t.Fatal(ts2)
|
t.Fatalf("want: %v, got: %v", ts, ts2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal([]byte(`123`), &ts2); err != nil {
|
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:
|
||||||
- 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: |
|
details: |
|
||||||
- if it's a web ui hook or somethin, then it'd only have file conflict if I modify without waiting
|
- 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
|
- but thats a step back from current todo solution
|
||||||
|
|
||||||
- todo: ez edit on many platforms, even offline and mobile
|
- todo: ez edit on many platforms, even offline and mobile
|
||||||
|
ts: Fri Dec 31 22:33:12 EST 2021
|
||||||
details: |
|
details: |
|
||||||
mobile view + complete method
|
mobile view + complete method
|
||||||
collab editing of file prob resolves mobile and other stuff...
|
collab editing of file prob resolves mobile and other stuff...
|
||||||
@@ -12,22 +14,35 @@ todo:
|
|||||||
web server access to ops
|
web server access to ops
|
||||||
is a web ui for mobile best solution?
|
is a web ui for mobile best solution?
|
||||||
let git be smart-ish and keep latest? would provide versioning OOTB without touching raw
|
let git be smart-ish and keep latest? would provide versioning OOTB without touching raw
|
||||||
|
scheduled: []
|
||||||
done:
|
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
|
- todo: YAML based todo
|
||||||
details:
|
ts: Fri Dec 31 22:33:12 EST 2021
|
||||||
because goddamnit a year of this shit
|
details: because goddamnit a year of this shit isn't significant on disk or in RAM
|
||||||
isn't significant on disk or in RAM for vim
|
for vim
|
||||||
- todo: yaml based todo for plaintext
|
- todo: yaml based todo for plaintext
|
||||||
|
ts: Fri Dec 31 22:33:12 EST 2021
|
||||||
details: a year isnt even a mb
|
details: a year isnt even a mb
|
||||||
- ez edit, start on many platforms
|
- ez edit, start on many platforms
|
||||||
- defer
|
- defer
|
||||||
- schedule
|
- schedule
|
||||||
- looping
|
- looping
|
||||||
- details
|
- details
|
||||||
- todo: let UI be UI for whatever platform
|
- let UI be UI for whatever platform
|
||||||
- tags
|
- tags
|
||||||
- todo: sub tasks
|
- todo: sub tasks
|
||||||
|
ts: Fri Dec 31 22:33:12 EST 2021
|
||||||
subtasks:
|
subtasks:
|
||||||
- a
|
- 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