diff options
| -rw-r--r-- | .config/waybar/config.jsonc | 424 | ||||
| -rwxr-xr-x | .config/waybar/modules/covid.sh | 39 | ||||
| -rwxr-xr-x[-rw-r--r--] | .config/waybar/modules/gamma.go | 18 | ||||
| -rwxr-xr-x | .config/waybar/modules/mpris.sh | 6 | ||||
| -rwxr-xr-x[-rw-r--r--] | .config/waybar/modules/todo.go | 5 | ||||
| -rw-r--r-- | .config/waybar/style.css | 27 |
6 files changed, 264 insertions, 255 deletions
diff --git a/.config/waybar/config.jsonc b/.config/waybar/config.jsonc index b117c3b..6c5b294 100644 --- a/.config/waybar/config.jsonc +++ b/.config/waybar/config.jsonc @@ -1,216 +1,212 @@ { - "layer": "top", - "position": "top", - "height": 25, - "gtk-layer-shell": true, - - // "modules-left": ["sway/mode", "sway/workspaces", "sway/window", "custom/mpris"], - "modules-left": ["sway/mode", "sway/workspaces", "custom/mpris"], - "modules-center": ["custom/weather", "clock#local", "clock#utc", "custom/toggl", "custom/todo"], - "modules-right": ["tray", "custom/covid", "cpu", "memory", "disk#root", "disk#home", "temperature", "idle_inhibitor", "backlight", "custom/gamma", "pulseaudio", "network#tailscale", "network", "battery"], - - "sway/workspaces": { - "disable-scroll": true, - "all-outputs": false, - "format": "{icon}", - "format-icons": { - "m": "", - "v": "", - "g": "", - "__vnc": "" - } - }, - "sway/window": { - "format": "{}", - "max-length": 100 - }, - "sway/mode": { - "format": "{}" - }, - "idle_inhibitor": { - "format": "{icon}", - "format-icons": { - "activated": "", - "deactivated": "" - } - }, - "tray": { - "spacing": 10 - }, - "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": "en_US.utf-8" - }, - "clock#utc": { - "timezone": "UTC", - "format": "({:<small>%Z</small> %H:%M})", - "tooltip-format": "{:%Z %z}" - }, - "disk#root": { - "path": "/", - "format": " <small>/ </small>{percentage_used}%" - }, - "disk#home": { - "path": "/home", - "format": "<small>/home </small>{percentage_used}%" - }, - "cpu": { - "format": " {}%", - "on-click": "$HOME/bin/swx -t -f -- htop --sort-key PERCENT_CPU" - }, - "memory": { - "format": " {}%", - "on-click": "$HOME/bin/swx -t -f -- htop --sort-key PERCENT_MEM" - }, - "temperature": { - "critical-threshold": 100, - "format": "{icon} {temperatureC}℃", - "format-icons": ["", "", "", ""] - }, - "backlight": { - "format": "{icon} {percent}%", - "format-icons": ["", "", ""], - "on-scroll-down": "light -A 5", - "on-scroll-up": "light -U 5", - // save current level - // then set to minimum brightness - "on-click-right": "light -O; light -S $(light -P)", - // revert to previously saved brightness - "on-click-middle": "light -I" - }, - "battery": { - "states": { - // "good": 95, - "warning": 30, - "critical": 15 - }, - "format": "{icon} {capacity}%", - "format-charging": " {capacity}%", - "format-plugged": " {capacity}%", - "format-alt": "{icon} {time}", - "format-full": "", - "format-icons": ["", "", "", ""] - }, - "network": { - "format-wifi": "{icon} ({signalStrength}%)", - "format-icons": ["", "", "", "", ""], - "format-ethernet": "", - "format-linked": " {ifname}", - "format-disconnected": " ", - "tooltip-format": "{ifname}: {ipaddr}/{cidr}\nssid: {essid}\nsignal: {signaldBm} dbm\ndown: {bandwidthDownBits}\nup: {bandwidthUpBits}", - "tooltip-format-disconnected": "disconnected", - "on-click": "swx -t -f iwctl" - }, - "network#tailscale": { - "interface": "tailscale0", - "format": "", - "tooltip-format": "{ifname}: {bandwidthUpBits} {bandwidthDownBits}", - "tooltip-format-disconnected": "disconnected", - "on-click": "doas rc-service tailscale start", - "on-click-right": "doas rc-service tailscale stop" - }, - "pulseaudio": { - "format": "{icon} {volume}%", - "format-bluetooth": "{icon} {volume}%", - "format-muted": " {volume}%", - "format-source": " {volume}%", - "format-source-muted": " {volume}%", - "format-icons": { - "headphones": "", - "handsfree": "", - "headset": "", - "phone": "", - "portable": "", - "car": "", - "default": ["", "", ""] - }, - "on-click-right": "pactl set-sink-mute @DEFAULT_SINK@ toggle", - "on-click": "swx -t -F '0.4' pulsemixer" - }, - "custom/mpris": { - "format": "{}", - "exec": "waybar-mpris --position --autofocus --interpolate --play --pause ", - "on-click": "waybar-mpris --send toggle", - "on-click-right": "waybar-mpris --send player-next", - "escape": true, - "max-width": 90, - "return-type": "json" - }, - "custom/toggl": { - "format": " {}", - "exec": "$HOME/.config/waybar/modules/toggl.lua 2>/dev/null", - "interval": 60 - }, - "custom/todo": { - "format": "{icon} {}", - "format-icons": { - "off": "", - "on": "" - }, - "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, - "return-type": "json" - }, - "custom/gamma": { - "format": "{icon}", - "format-icons": { - "day": "", - "night": "" - }, - "exec-if": "pgrep wlsunset", - "exec": "env GAMMA_COMMAND='wlsunset -l $HOME_LAT -L $HOME_LON -p' $HOME/.config/waybar/modules/waybar-gamma", - "return-type": "json", - "on-click": "pkill -x -USR1 gamma", - "on-click-right": "pkill -x -HUP waybar-gamma" - }, - "custom/weather": { - "format": "{icon} {percentage}℃", - "format-icons": { - "sunny": "", - "partlycloudy": "", - "cloudy": "", - "verycloudy": "", - "fog": "", - "lightrain": "", - "heavyrain": "", - "hail": "", - "thunder": "", - "lightsnow": "", - "heavysnow": "", - "snowrain": "" - }, - "exec": "$HOME/.config/waybar/modules/weather.sh", - "interval": 600, - "return-type": "json", - "tooltip": true, - // "signal": 4, - // "on-click-right": "pkill -SIGRTMIN+5 waybar", - "on-click": "swx -t env REPORT=1 $HOME/.config/waybar/modules/weather.sh" - }, - "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" - }, - // "custom/im": { - // "format": "{}", - // "exec": "printf ''", - // "exec-if": "pgrep anthywl", - // "interval": 5 - // } + "modules-left": ["sway/mode", "sway/workspaces", "custom/mpris"], + + "sway/workspaces": { + "disable-scroll": true, + "format": "{icon}", + "format-icons": { + "m": "", + "v": "", + "g": "", + "__vnc": "" + } + }, + + "custom/mpris": { + "exec-on-event": false, + "max-width": 60, + "escape": true, + "on-click": "playerctl play-pause", + "on-click-right": "playerctl next", + // "exec": "env YAEGI_SYSCALL=1 YAEGI_UNRESTRICTED=1 ${HOME}/.config/waybar/modules/mpris.go", + "exec": "${HOME}/.config/waybar/modules/mpris.sh", + "return-type": "json" + }, + + // ------------------------------------------------------------------------ // + + "modules-center": ["custom/weather", "clock#local", "clock#utc", "custom/toggl"], + + "custom/weather": { + "format": "{icon} {percentage}℃", + "format-icons": { + "sunny": "", + "partlycloudy": "", + "cloudy": "", + "verycloudy": "", + "fog": "", + "lightrain": "", + "heavyrain": "", + "hail": "", + "thunder": "", + "lightsnow": "", + "heavysnow": "", + "snowrain": "" + }, + "exec": "$HOME/.config/waybar/modules/weather.sh", + "interval": 600, + "return-type": "json", + "tooltip": true, + "on-click": "swx -t env REPORT=1 $HOME/.config/waybar/modules/weather.sh" + }, + + "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": "en_US.utf-8" + }, + + "clock#utc": { + "timezone": "UTC", + "format": "({:<small>%Z</small> %H:%M})", + "tooltip-format": "{:%Z %z}" + }, + + "custom/todo": { + "format": "{icon} {}", + "format-icons": { + "off": "", + "on": "" + }, + "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, + "return-type": "json" + }, + + // ------------------------------------------------------------------------ // + "modules-right": ["tray", "custom/covid", "cpu", "memory", "disk#root", "disk#home", "temperature", "idle_inhibitor", "backlight", "custom/gamma", "pulseaudio", "network#tailscale", "network", "battery"], + + "tray": { + "spacing": 10 + }, + + "custom/covid": { + "format": "{icon} {}", + "format-icons": { + "gray": "", + "green": "", + "yellow": "", + "orange": "", + "red": "", + "darkred": "", + "darkdarkred": "" + }, + "exec": "$HOME/.config/waybar/modules/covid.sh", + "interval": 86400, + "return-type": "json" + }, + + "disk#root": { + "path": "/", + "format": " <small>/ </small>{percentage_used}%" + }, + + "disk#home": { + "path": "/home", + "format": "<small>/home </small>{percentage_used}%" + }, + + "cpu": { + "format": " {}%", + "on-click": "$HOME/bin/swx -t -f -- htop --sort-key PERCENT_CPU" + }, + + "memory": { + "format": " {}%", + "on-click": "$HOME/bin/swx -t -f -- htop --sort-key PERCENT_MEM" + }, + + "temperature": { + "critical-threshold": 100, + "format": "{icon} {temperatureC}℃", + "format-icons": ["", "", "", ""] + }, + + "idle_inhibitor": { + "format": "{icon}", + "format-icons": { + "activated": "", + "deactivated": "" + } + }, + + "backlight": { + "format": "{icon}", + "format-icons": ["", "", ""], + "on-scroll-down": "light -A 5", + "on-scroll-up": "light -U 5", + // save current level + // then set to minimum brightness + "on-click-right": "light -O; light -S $(light -P)", + // revert to previously saved brightness + "on-click-middle": "light -I" + }, + + "custom/gamma": { + "format": "{icon}", + "format-icons": { + "day": "", + "night": "", + "dusk": "?", + "dawn": "?" + }, + "exec": "env GAMMA_COMMAND='wlsunset -l $HOME_LAT -L $HOME_LON -p' YAEGI_SYSCALL=1 YAEGI_UNRESTRICTED=1 ${HOME}/.config/waybar/modules/gamma.go", + "return-type": "json" + }, + + "pulseaudio": { + "format": "{icon} {volume}%", + "format-bluetooth": "{icon} {volume}%", + "format-muted": " {volume}%", + "format-source": " {volume}%", + "format-source-muted": " {volume}%", + "format-icons": { + "headphones": "", + "handsfree": "", + "headset": "", + "phone": "", + "portable": "", + "car": "", + "default": ["", "", ""] + }, + "on-click-right": "pactl set-sink-mute @DEFAULT_SINK@ toggle", + "on-click": "swx -t -F '0.4' pulsemixer" + }, + + "network#tailscale": { + "interface": "tailscale0", + "format": "", + "tooltip-format": "{ifname}: {bandwidthUpBits} {bandwidthDownBits}", + "tooltip-format-disconnected": "disconnected", + "on-click": "doas rc-service tailscale start", + "on-click-right": "doas rc-service tailscale stop" + }, + + "network": { + "format-wifi": "{icon} ({signalStrength}%)", + "format-icons": ["", "", "", "", ""], + "format-ethernet": "", + "format-linked": " {ifname}", + "format-disconnected": " ", + "tooltip-format": "{ifname}: {ipaddr}/{cidr}\nssid: {essid}\nsignal: {signaldBm} dbm\ndown: {bandwidthDownBits}\nup: {bandwidthUpBits}", + "tooltip-format-disconnected": "disconnected", + "on-click": "swx -t -f iwctl" + }, + + "battery": { + "states": { + // "good": 95, + "warning": 30, + "critical": 15 + }, + "format": "{icon} {capacity}%", + "format-charging": " {capacity}%", + "format-plugged": " {capacity}%", + "format-alt": "{icon} {time}", + "format-full": "", + "format-icons": ["", "", "", ""] + }, } diff --git a/.config/waybar/modules/covid.sh b/.config/waybar/modules/covid.sh index 9f1860c..e44c108 100755 --- a/.config/waybar/modules/covid.sh +++ b/.config/waybar/modules/covid.sh @@ -1,7 +1,10 @@ #!/bin/sh set -e -[ -n "$DEBUG" ] && { set -x; curl_args='-v'; } +[ -n "$DEBUG" ] && { + set -x + curl_args='-v' +} # check requirements for tool in awk curl jq flock; do @@ -18,30 +21,32 @@ fields='GEN,RS,EWZ,EWZ_BL,BL_ID,cases,cases_per_100k,cases7_per_100k,cases7_bl_p # see https://experience.arcgis.com/experience/478220a4c454480e823b17327b2bf1d4 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') +_data=$(curl -sSL -H 'Accept: application/json' ${curl_args} "${uri}" | jq -r '.features[0].attributes') [ -z "${_data}" ] && printf "{}\n" HISTFILE=${HOME}/covid-history.csv -loc=$(printf "${_data}" | jq -r '.GEN') -last_update=$(printf "${_data}" | jq -r '.last_update') +loc=$(printf "%s" "${_data}" | jq -r '.GEN') +last_update=$(printf "%s" "${_data}" | jq -r '.last_update') # printf "${_data}" | jq -r '.' -incidence_f=$(printf "%.1f" $(printf "${_data}" | jq -r '.cases7_bl_per_100k')) +incidence_f=$(printf "%.1f" "$(printf "%s" "${_data}" | jq -r '.cases7_bl_per_100k')") incidence_i=$(printf "%.0f" "${incidence_f}") # store -tmp_HISTFILE=$(mktemp -u --tmpdir waybar-module-covid.XXXXX) -( - cat ${HISTFILE} - ts=$(printf "${last_update}" | cut -d',' -f1 | tr '.' '-') - printf "%s,%s\n" "${ts}" "${incidence_f}" -) | uniq | tee ${tmp_HISTFILE} >/dev/null -flock -x ${HISTFILE} mv ${tmp_HISTFILE} ${HISTFILE} +if [ -n "${last_update}" ] && [ -n "${incidence_f}" ]; then + tmp_HISTFILE=$(mktemp -u --tmpdir waybar-module-covid.XXXXX) + ( + cat "${HISTFILE}" + ts=$(printf "%s" "${last_update}" | cut -d',' -f1 | tr '.' '-') + printf "%s,%s\n" "${ts}" "${incidence_f}" + ) | uniq | tee "${tmp_HISTFILE}" >/dev/null + flock -x "${HISTFILE}" mv "${tmp_HISTFILE}" "${HISTFILE}" +fi -mxy=$(awk -F',' '{y=y+$2} END{print ((NR*(NR+1))/2)/NR, y/NR}' "${HISTFILE}") -trend=$(awk -F',' --assign="mx=$(printf "$mxy" | cut -d' ' -f1)" --assign="my=$(printf "$mxy" | cut -d' ' -f2)" '{up= up+(NR-mx)*($2-my); down= down+(NR-mx)**2} END{if(down==0){print 0}else{print up/down};}' "${HISTFILE}") +mxy=$(tail -n 7 "${HISTFILE}" | awk -F',' '{y=y+$2} END{print ((NR*(NR+1))/2)/NR, y/NR}') +trend=$(awk -F',' --assign="mx=$(printf "%s" "$mxy" | cut -d' ' -f1)" --assign="my=$(printf "%s" "$mxy" | cut -d' ' -f2)" '{up= up+(NR-mx)*($2-my); down= down+(NR-mx)**2} END{if(down==0){print 0}else{print up/down};}' "${HISTFILE}") trend_arrow="" -[ $(printf "%.0f" ${trend}) -gt 0 ] && trend_arrow="" -[ $(printf "%.0f" ${trend}) -lt 0 ] && trend_arrow="" +[ "$(printf "%.0f" "${trend}")" -gt 0 ] && trend_arrow="" +[ "$(printf "%.0f" "${trend}")" -lt 0 ] && trend_arrow="" color='green' if [ "${incidence_i}" -eq "0" ]; then @@ -71,7 +76,7 @@ tooltip=" last update: ${last_update} history (${trend_arrow}): -$(awk -F, '{print $1 " " $2}' ${HISTFILE} | tail -n10) +$(awk -F, '{print $1 " " $2}' "${HISTFILE}" | tail -n10 | tac) " jq -nr \ diff --git a/.config/waybar/modules/gamma.go b/.config/waybar/modules/gamma.go index 2a91cdb..9813cc8 100644..100755 --- a/.config/waybar/modules/gamma.go +++ b/.config/waybar/modules/gamma.go @@ -1,5 +1,5 @@ -// usage: -// go build -o waybar-gammastep gammastep.go +#!/usr/bin/env yaegi + package main import ( @@ -8,12 +8,14 @@ import ( "os" "os/exec" "os/signal" + "runtime" "strings" - . "syscall" ) func main() { + runtime.GOMAXPROCS(1) + var ( update = make(chan os.Signal, 1) cancel = make(chan os.Signal, 1) @@ -23,12 +25,11 @@ func main() { // could use golang.org/x/sys/unix.Prctl here // but I want to avoid the dependency - if _, _, e := Syscall6(SYS_PRCTL, + if _, _, e := Syscall6(uintptr(SYS_PRCTL), uintptr(PR_SET_PDEATHSIG), uintptr(SIGTERM), 0, 0, 0, 0); e != 0 { - log.Printf("error: %v", e) - os.Exit(1) + log.Fatalf("error: %v", e) } lookup() @@ -38,8 +39,10 @@ func main() { switch sig { case SIGUSR1: printJson("day") + // TODO(robert): toggle wlsunset off? case SIGUSR2: printJson("night") + // TODO(robert): toggle wlsunset on? case SIGHUP: lookup() } @@ -65,10 +68,9 @@ func lookup() { printJson("unknown") return } - log.Println(cmdEnv) b, err := exec.Command("bash", "-c", cmdEnv).Output() if err != nil { - log.Printf("error: %v", err) + log.Fatalf("error: %v", err) return } phase := strings.TrimSpace(string(b)) diff --git a/.config/waybar/modules/mpris.sh b/.config/waybar/modules/mpris.sh new file mode 100755 index 0000000..5f33f5e --- /dev/null +++ b/.config/waybar/modules/mpris.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +set -eo pipefail +[ -n "$DEBUG" ] && set -x + +playerctl -sF metadata -f '"{{artist}}","{{album}}","{{title}}","{{duration(position)}}","{{playerName}}","{{lc(status)}}"' | awk -F',' -f "${HOME}/.config/waybar/modules/mpris.awk" diff --git a/.config/waybar/modules/todo.go b/.config/waybar/modules/todo.go index 97daaa4..2692ec9 100644..100755 --- a/.config/waybar/modules/todo.go +++ b/.config/waybar/modules/todo.go @@ -1,3 +1,5 @@ +#!/usr/bin/env yaegi + // # Documentation // we try to read a file pointed to by WAYBAR_TODO_FILE. // While no particular format is assumed, we recommend @@ -16,6 +18,7 @@ import ( "os" "os/signal" "regexp" + "runtime" "strings" "time" @@ -127,6 +130,8 @@ func init() { } func main() { + runtime.GOMAXPROCS(1) + var ( updateC = make(chan os.Signal, 1) cancelC = make(chan os.Signal, 1) diff --git a/.config/waybar/style.css b/.config/waybar/style.css index f315b12..9c0cfc2 100644 --- a/.config/waybar/style.css +++ b/.config/waybar/style.css @@ -33,6 +33,16 @@ font-size: 10pt; } +window#waybar { + background: @background; + color: @foreground; + /* padding: 0 0.3rem; */ +} +window#waybar.hidden { + opacity: 0; +} + + #window, #mode, #clock, @@ -52,7 +62,7 @@ #custom-todo, #custom-covid, #tray { - border-top: 1px solid @dimmeddarker; + /* border-top: 1px solid @dimmeddarker; */ padding: 0 0.1rem; margin: 0 0.2rem; color: @foreground; @@ -120,21 +130,6 @@ transition-duration: 0.01s; } -#window { - /* border-top: 1px solid @accentdarker; */ - border-top: none; - padding: 0 0.3rem; -} -window#waybar { - background: @background; - color: @foreground; -} -window#waybar.empty { - /* border-top: none; */ -} -window#waybar.solo {} -/* window#waybar.<appid> {} */ - #mode { font-style: italic; color: @background; |