-
Notifications
You must be signed in to change notification settings - Fork 1
/
process.go
59 lines (53 loc) · 1009 Bytes
/
process.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package edist
import (
"crypto/md5"
"errors"
"os"
"os/exec"
"runtime"
)
func edit(filepath string) (updated bool, err error) {
before, err := getMD5(filepath)
if err != nil {
return
}
err = openEditor(filepath)
if err != nil {
return
}
after, err := getMD5(filepath)
if err != nil {
return
}
updated = before != after
return
}
func getMD5(filepath string) ([16]byte, error) {
binary, err := os.ReadFile(filepath)
if err != nil {
return [16]byte{}, err
}
return md5.Sum(binary), nil
}
func openEditor(filepath string) error {
cmd := exec.Command("vi", filepath)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
func restartStickies() error {
if err := exec.Command("killall", "Stickies").Run(); err != nil {
return err
}
if err := exec.Command("open", "-a", "stickies").Run(); err != nil {
return err
}
return nil
}
func checkOS() error {
if runtime.GOOS != "darwin" {
return errors.New("unsupported os")
}
return nil
}