diff options
| author | Robert Günzler <r@gnzler.io> | 2021-04-22 13:11:10 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2021-04-26 02:09:47 +0200 |
| commit | ed3a44d2b34dfe76c1cb51e97dc9091660c4c0ba (patch) | |
| tree | e4b7b04ff4547e352ff4f76dec9938108b7d93a2 /.config | |
| parent | cf2652815f6e23cac7d1fcf64e2820e37d0b33b8 (diff) | |
waybar/todo: just load file from an env var
Diffstat (limited to '')
| -rw-r--r-- | .config/waybar/config | 2 | ||||
| -rw-r--r-- | .config/waybar/modules/todo.go | 42 |
2 files changed, 23 insertions, 21 deletions
diff --git a/.config/waybar/config b/.config/waybar/config index 3bdf3b3..544661d 100644 --- a/.config/waybar/config +++ b/.config/waybar/config @@ -157,7 +157,7 @@ "off": "", "on": "" }, - "exec": "$HOME/.config/waybar/modules/waybar-todo", + "exec": "env WAYBAR_TODO_FILE=$HOME/.zk/todo.md $HOME/.config/waybar/modules/waybar-todo", "on-click": "pkill -x -USR1 waybar-todo", "on-click-right": "pkill -x -USR2 waybar-todo", "escape": true, diff --git a/.config/waybar/modules/todo.go b/.config/waybar/modules/todo.go index 4f403f5..97daaa4 100644 --- a/.config/waybar/modules/todo.go +++ b/.config/waybar/modules/todo.go @@ -1,6 +1,5 @@ // # Documentation -// we try to read a file pointed to by WAYBAR_TODO_FILE -// or `nb show --path todo`. +// we try to read a file pointed to by WAYBAR_TODO_FILE. // While no particular format is assumed, we recommend // Markdown. // We extract the todos from the top-level list items @@ -15,7 +14,6 @@ import ( "encoding/json" "log" "os" - "os/exec" "os/signal" "regexp" "strings" @@ -26,7 +24,6 @@ import ( ) const ( - TODO_LINE_CHAR string = "* " TODO_INACTIVE_STRING string = "" TODO_LABEL_REGEX string = `\[\[!(.*)\]\]` ) @@ -58,14 +55,20 @@ func readTodofile2(path string) ([]todoItem, error) { if err != nil { return nil, err } - var ( - todos []todoItem - ) + var todos []todoItem for lr := bufio.NewScanner(f); lr.Scan(); { - if !strings.HasPrefix(lr.Text(), TODO_LINE_CHAR) { + skip := 0 + switch { + case strings.HasPrefix(lr.Text(), "*"): + skip = 2 + case strings.HasPrefix(lr.Text(), "- [ ]"): + skip = 6 + case strings.HasPrefix(lr.Text(), "- [x]"): + fallthrough + default: continue } - ti := todoItem{text: lr.Text()[2:]} + ti := todoItem{text: lr.Text()[skip:]} matches := labelre.FindAllStringSubmatch(ti.text, -1) if matches != nil && len(matches) > 0 { ti.label = matches[0][1] @@ -117,9 +120,7 @@ func update() error { return printJson(text, strings.Join(tooltip, "\n"), []string{"on", extraClass}, "on", 1) } -var ( - labelre *regexp.Regexp -) +var labelre *regexp.Regexp func init() { labelre = regexp.MustCompile(TODO_LABEL_REGEX) @@ -141,14 +142,15 @@ func main() { } if todofile == "" { - // get from nb(1) - nb := exec.Command("sh", "-c", "nb show --no-color --path todo") - nb_output, err := nb.Output() - if err != nil { - e := err.(*exec.ExitError) - log.Fatalf("error: finding todofile via nb: %s", e.Stderr) - } - todofile = strings.TrimSpace(string(nb_output)) + panic("missing TODO file") + // // get from nb(1) + // nb := exec.Command("sh", "-c", "nb show --no-color --path todo") + // nb_output, err := nb.Output() + // if err != nil { + // e := err.(*exec.ExitError) + // log.Fatalf("error: finding todofile via nb: %s", e.Stderr) + // } + // todofile = strings.TrimSpace(string(nb_output)) } log.Printf("watching %q", todofile) |