summary refs log tree commit diff
path: root/.config/waybar/modules
diff options
context:
space:
mode:
Diffstat (limited to '.config/waybar/modules')
-rwxr-xr-x.config/waybar/modules/covid.sh39
-rwxr-xr-x[-rw-r--r--].config/waybar/modules/gamma.go18
-rwxr-xr-x.config/waybar/modules/mpris.sh6
-rwxr-xr-x[-rw-r--r--].config/waybar/modules/todo.go5
4 files changed, 43 insertions, 25 deletions
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)