Ver Código Fonte

~/.bin/working-time.go: Notify about break duration

This also adds a permanent notification if you're taking a break, so you
don't forget to end it.
Lu Stadler 7 anos atrás
pai
commit
2f9c9caa6c
1 arquivos alterados com 14 adições e 0 exclusões
  1. 14 0
      .bin/working-time.go

+ 14 - 0
.bin/working-time.go

@ -8,6 +8,7 @@ import (
8 8
	"encoding/json"
9 9
	"fmt"
10 10
	"os"
11
	"os/exec"
11 12
	"path"
12 13
	"time"
13 14
)
@ -40,9 +41,11 @@ func main() {
40 41
			dur := now.Sub(*day.BreakStart)
41 42
			day.Break += dur
42 43
			day.BreakStart = nil
44
			notifyCompletion(fmt.Sprintf("took a %s break", dur), 0)
43 45
			fmt.Fprintf(os.Stderr, "took a %s break\n", dur)
44 46
		} else {
45 47
			day.BreakStart = &now
48
			notifyCompletion("taking a break", 10*time.Hour)
46 49
		}
47 50
		writeDay(dayFile, day)
48 51
	}
@ -53,6 +56,7 @@ func main() {
53 56
			fmt.Fprintln(os.Stderr, err)
54 57
			os.Exit(1)
55 58
		}
59
		notifyCompletion(fmt.Sprintf("took a %s break", dur), 0)
56 60
		fmt.Fprintf(os.Stderr, "took a %s break\n", dur)
57 61
		day.Break += dur
58 62
		writeDay(dayFile, day)
@ -98,3 +102,13 @@ func writeDay(path string, day Day) {
98 102
		os.Exit(1)
99 103
	}
100 104
}
105
106
func notifyCompletion(msg string, dur time.Duration) {
107
	args := make([]string, 0, 1)
108
	if dur != 0 {
109
		args = append(args, "--expire-time", fmt.Sprintf("%d", int(dur.Seconds()*1000)))
110
	}
111
	args = append(args, msg)
112
	notifyCmd := exec.Command("notify-send", args...)
113
	notifyCmd.Run()
114
}