diff options
| author | Robert Günzler <r@gnzler.io> | 2021-02-23 13:36:27 +0100 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2021-04-26 02:09:45 +0200 |
| commit | 4b71908c30807c9d726e83378e04ccae28dff334 (patch) | |
| tree | ab3c37125a69803ffdaba7cdcac9014c437f3215 /.config | |
| parent | 6cb604cdeb78b151d7e179d4f34f00101c912282 (diff) | |
waybar: update 2021-02-23T13:36:34Z+01:00
Diffstat (limited to '.config')
| -rw-r--r-- | .config/waybar/config | 28 | ||||
| -rwxr-xr-x | .config/waybar/modules/covid.sh | 43 | ||||
| -rw-r--r-- | .config/waybar/modules/todo.go | 68 | ||||
| -rw-r--r-- | .config/waybar/style.css | 101 |
4 files changed, 156 insertions, 84 deletions
diff --git a/.config/waybar/config b/.config/waybar/config index 557dafe..f8443b3 100644 --- a/.config/waybar/config +++ b/.config/waybar/config @@ -7,7 +7,7 @@ "modules-left": ["sway/mode", "sway/workspaces", "sway/window", "custom/mpris"], "modules-center": ["custom/weather", "clock#local", "clock#utc", "custom/toggl", "custom/todo"], - "modules-right": ["tray", "cpu", "memory", "disk#root", "disk#home", "temperature", "idle_inhibitor", "backlight", "custom/gammastep", "pulseaudio", "network#vpn", "network#tailscale", "network", "battery"], + "modules-right": ["tray", "custom/covid", "cpu", "memory", "disk#root", "disk#home", "temperature", "idle_inhibitor", "backlight", "custom/gammastep", "pulseaudio", "network#vpn", "network#tailscale", "network", "battery"], "sway/workspaces": { "disable-scroll": true, @@ -40,7 +40,8 @@ "clock#local": { "format": "{:<i>%a</i> %d %b <b>%H:%M</b>}", "tooltip-format": "TZ: {:%Z %z}\n\n{calendar}", - "locale": "ja_JP.utf-8" + // "locale": "ja_JP.utf-8" + "locale": "en_US.utf-8" }, "clock#utc": { "timezone": "UTC", @@ -148,14 +149,13 @@ "custom/toggl": { "format": " {}", "exec": "$HOME/.config/waybar/modules/toggl.lua 2>/dev/null", - "interval": 30 + "interval": 60 }, "custom/todo": { "format": "{icon} {}", "format-icons": { - "off": "!", - "on": "!", - // "work": "" + "off": "", + "on": "" }, "exec": "$HOME/.config/waybar/modules/waybar-todo", "on-click": "pkill -x -USR1 waybar-todo", @@ -198,5 +198,21 @@ // "signal": 4, // "on-click-right": "pkill -SIGRTMIN+5 waybar", "on-click": "swx -t env REPORT=1 $HOME/.config/waybar/modules/weather.sh Berlin" + }, + "custom/covid": { + "format": "{icon} {}", + "format-icons": { + "gray": "", + "green": "", + "yellow": "", + "orange": "", + "red": "!", + "darkred": "!!", + "darkdarkred": "" + }, + "exec": "$HOME/.config/waybar/modules/covid.sh", + "interval": 86400, + "tooltip": true, + "return-type": "json" } } diff --git a/.config/waybar/modules/covid.sh b/.config/waybar/modules/covid.sh new file mode 100755 index 0000000..b30321c --- /dev/null +++ b/.config/waybar/modules/covid.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +set -e +[ -n "$DEBUG" ] && { set -x; curl_args='-v'; } + +# incidence = (sumCasesLast7Days / EWZ) * 100000 +lat=52.54 +lon=13.44 +fields='GEN,RS,EWZ,EWZ_BL,BL_ID,cases,cases_per_100k,cases7_per_100k,cases7_bl_per_100k,last_update,BL,IBZ' +uri="https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=${fields}&geometry=${lon}%2C${lat}&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelWithin&returnGeometry=false&outSR=4326&f=json" + +_data=$(curl -sSL -H 'Accept: application/json' ${curl_args} ${uri} | jq -r '.features[0].attributes') +loc=$(printf "${_data}" | jq -r '.GEN') +incidence_f=$(printf "%.1f" $(printf "${_data}" | jq -r '.cases7_bl_per_100k')) +incidence_i=$(printf "%.0f" "${incidence_f}") + +color='green' +if [ "${incidence_i}" -eq "0" ]; then + color='gray' +fi +if [ "${incidence_i}" -gt "1" ]; then + color='green' +fi +if [ "${incidence_i}" -gt "25" ]; then + color='yellow' +fi +if [ "${incidence_i}" -gt "35" ]; then + color='orange' +fi +if [ "${incidence_i}" -gt "50" ]; then + color='red' +fi +if [ "${incidence_i}" -gt "100" ]; then + color='darkred' +fi +if [ "${incidence_i}" -gt "250" ]; then + color='darkdarkred' +fi + +jq -nr \ + --arg "if" "${incidence_f}" \ + --arg "ii" "${incidence_i}" \ + "{ text: \$if, percentage: \$ii, class: \"${color}\", alt: \"${color}\", tooltip: \"7 Tage Inzidenz für \\n${loc}\" } | @text" diff --git a/.config/waybar/modules/todo.go b/.config/waybar/modules/todo.go index 449f991..4f403f5 100644 --- a/.config/waybar/modules/todo.go +++ b/.config/waybar/modules/todo.go @@ -11,17 +11,14 @@ package main import ( - "bytes" + "bufio" "encoding/json" - "fmt" - "io/ioutil" "log" "os" "os/exec" "os/signal" "regexp" "strings" - "text/scanner" "time" "github.com/fsnotify/fsnotify" @@ -29,7 +26,7 @@ import ( ) const ( - TODO_LINE_CHAR rune = '*' + TODO_LINE_CHAR string = "* " TODO_INACTIVE_STRING string = "" TODO_LABEL_REGEX string = `\[\[!(.*)\]\]` ) @@ -56,47 +53,26 @@ type todoItem struct { label string } -func readTodofile(path string) ([]todoItem, error) { - content, err := ioutil.ReadFile(path) +func readTodofile2(path string) ([]todoItem, error) { + f, err := os.Open(path) if err != nil { - return nil, fmt.Errorf("reading file: %v", err) + return nil, err } - var ( - sc scanner.Scanner - validLine bool - todos []todoItem + todos []todoItem ) - sc.Init(bytes.NewReader(content)) - sc.Filename = path - sc.Whitespace ^= 1<<'\n' | 1<<' ' // don't skip newlines or spaces - sc.Mode ^= scanner.GoTokens - for tok := sc.Scan(); tok != scanner.EOF; tok = sc.Scan() { - switch { - // a valid line stats with TODO_LINE_CHAR - // followed by a space - // we strip them before appending the line array - case tok == TODO_LINE_CHAR && sc.Peek() == ' ': - validLine = true - _ = sc.Scan() // swallow the space - todos = append(todos, todoItem{}) // grow the array - - case tok == '\n': - validLine = false - if len(todos) > 0 { - idx := len(todos) - 1 - matches := labelre.FindAllStringSubmatch(todos[idx].text, -1) - if matches != nil && len(matches) > 0 { - todos[idx].label = matches[0][1] - todos[idx].text = strings.TrimSpace( - strings.Replace(todos[idx].text, matches[0][0], "", 1)) - } - } - - case validLine: - todos[len(todos)-1].text = todos[len(todos)-1].text + sc.TokenText() + for lr := bufio.NewScanner(f); lr.Scan(); { + if !strings.HasPrefix(lr.Text(), TODO_LINE_CHAR) { + continue } - + ti := todoItem{text: lr.Text()[2:]} + matches := labelre.FindAllStringSubmatch(ti.text, -1) + if matches != nil && len(matches) > 0 { + ti.label = matches[0][1] + ti.text = strings.TrimSpace( + strings.Replace(ti.text, matches[0][0], "", 1)) + } + todos = append(todos, ti) } return todos, nil } @@ -115,15 +91,15 @@ func update() error { active = false } if !active { - return printJson(TODO_INACTIVE_STRING, "* inactive *", []string{"off"}, "todo-off", 0) + return printJson(TODO_INACTIVE_STRING, "* inactive *", []string{"off"}, "off", 0) } - todos, err := readTodofile(todofile) + todos, err := readTodofile2(todofile) if err != nil { return err } var ( text string - tooltip string + tooltip []string extraClass string ) for _, item := range todos { @@ -136,9 +112,9 @@ func update() error { continue } // render out the rest of the todos into the tooltip - tooltip = strings.Join([]string{tooltip, item.text}, "\n") + tooltip = append(tooltip, item.text) } - return printJson(text, tooltip, []string{"on", extraClass}, "todo-on", 1) + return printJson(text, strings.Join(tooltip, "\n"), []string{"on", extraClass}, "on", 1) } var ( diff --git a/.config/waybar/style.css b/.config/waybar/style.css index d28b142..35b73b6 100644 --- a/.config/waybar/style.css +++ b/.config/waybar/style.css @@ -19,18 +19,18 @@ @define-color accentdarker #3e355a; @define-color foreground @color07; -@define-color background @color00; +@define-color background rgba(15,15,15, 0.96); /* @define-color dimmed #777777; */ /* @define-color dimmeddarker #302a29; */ -@define-color dimmed @color05; -@define-color dimmeddarker #292929; +@define-color dimmed #404540; /*@color05;*/ +@define-color dimmeddarker @color00; @define-color urgent #9f353a; * { border: none; border-radius: 0; font-family: Iosevka SS14, Noto Mono, Material Design Icons, Font Awesome; - font-size: 11pt; + font-size: 10pt; } #window, @@ -50,12 +50,27 @@ #custom-weather, #custom-mpris, #custom-todo, +#custom-covid, #tray { - border-top: 2px solid @dimmeddarker; - padding: 0 0.3rem; - margin: 0 0.25rem; + border-top: 1px solid @dimmeddarker; + padding: 0 0.1rem; + margin: 0 0.2rem; color: @foreground; } + +#cpu, +#memory, +#disk, +#temperature, +#idle_inhibitor, +#backlight, +#custom-gammastep, +#network.vpn, +#network.tailscale, +#custom-covid { + color: @dimmed; +} + #cpu:hover, #memory:hover, #backlight:hover, @@ -108,15 +123,16 @@ } #window { - /* border-top: 2px solid @accentdarker; */ + /* border-top: 1px solid @accentdarker; */ border-top: none; + padding: 0 0.3rem; } window#waybar { background: @background; color: @foreground; } window#waybar.empty { - border-top: none; + /* border-top: none; */ } window#waybar.solo {} /* window#waybar.<appid> {} */ @@ -130,8 +146,8 @@ window#waybar.solo {} #clock {} #clock.local { - margin-right: 0; - padding-right: 0; + /* margin-right: 0; */ + /* padding-right: 0; */ } #clock.utc { color: @dimmed; @@ -139,8 +155,8 @@ window#waybar.solo {} #disk.root {} #disk.home { - margin-left: 0; - padding-left: 0; + /* margin-left: 0; */ + /* padding-left: 0; */ } #battery {} @@ -176,24 +192,24 @@ label:focus { } #network {} #network.disconnected { - border-top: 2px solid @urgent; + border-top: 1px solid @urgent; color: @dimmed; } #network.vpn.disconnected { - border-top: 2px solid @dimmeddarker; + border-top: 1px solid @dimmeddarker; } #network.vpn:not(.disconnected) { - border-top: 2px solid @color11; + border-top: 1px solid @color11; } #network.tailscale.disconnected { - border-top: 2px solid @dimmeddarker; + border-top: 1px solid @dimmeddarker; } #network.tailscale:not(.disconnected) { - border-top: 2px solid @color14; + border-top: 1px solid @color14; } #pulseaudio {} #pulseaudio.muted { - border-top: 2px solid @urgent; + border-top: 1px solid @urgent; color: @dimmed; } @@ -206,32 +222,31 @@ label:focus { #tray {} #idle_inhibitor { - color: @dimmed; } #idle_inhibitor.activated { - color: unset; - border-top: 2px solid @color02; + color: @foreground; + border-top: 1px solid @color02; } #custom-mpris { - min-width: 100px; color: @foreground; - border-top: 2px solid @color04; + border-top: 1px solid @color04; } #custom-toggl { color: @foreground; - border-top: 2px solid @urgent; + border-top: 1px solid @urgent; } #custom-todo.off { - color: red; - border-top: 2px solid @dimmeddarker; + color: @dimmed; + border-top: 1px solid @dimmeddarker; + padding: 0 0 0 0.4rem; } #custom-todo.on { color: @foreground; + border-top: 1px solid @urgent; font-weight: bold; - border-top: none; padding: 0 0.6rem 0 0.4rem; } #custom-todo.work { @@ -245,7 +260,7 @@ label:focus { } } #custom-gammastep.night { - border-top: 2px solid @color12; + border-top: 1px solid @color12; color: @foreground; animation-name: flash; animation-duration: 0.3s; @@ -257,13 +272,35 @@ label:focus { } #custom-gammastep.off, #custom-gammastep.unknown { - border-top: 2px solid @urgent; + border-top: 1px solid @urgent; color: @dimmed; } #custom-weather { color: @dimmed; } -#custom-weather.sunny { - color: rgba(255,255,0, 0.6); + +#custom-covid.green { + /* border-top: 1px solid #00cc00; */ + /* color: #00cc00; */ +} +#custom-covid.yellow { + /* border-top: 1px solid #f7dd31; */ + /* color: #f7dd31; */ +} +#custom-covid.orange { + /* border-top: 1px solid #faa31b; */ + /* color: #faa31b; */ +} +#custom-covid.red { + /* border-top: 1px solid #f92206; */ + /* color: #f92206; */ +} +#custom-covid.darkred { + /* border-top: 1px solid #c01a00; */ + /* color: #c01a00; */ +} +#custom-covid.darkdarkred { + /* border-top: 1px solid #941100; */ + /* color: #941100; */ } |