From 4eb98175c021f0e1d15520f6cfb7831e14333ee0 Mon Sep 17 00:00:00 2001 From: ahwx Date: Thu, 26 Feb 2026 00:28:33 +0100 Subject: [PATCH] feat: adds uptime plugin to sketchybar --- modules/home/sketchybar/plugins/uptime.sh | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 modules/home/sketchybar/plugins/uptime.sh diff --git a/modules/home/sketchybar/plugins/uptime.sh b/modules/home/sketchybar/plugins/uptime.sh new file mode 100644 index 0000000..bb059c0 --- /dev/null +++ b/modules/home/sketchybar/plugins/uptime.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +boot=$(sysctl -n kern.boottime) +boot=${boot/\{ sec = /} +boot=${boot/,*/} +now=$(date +%s) +seconds=$((now - boot)) +d="$((seconds / 60 / 60 / 24)) days" +h="$((seconds / 60 / 60 % 24)) hours" +m="$((seconds / 60 % 60)) minutes" + +# Remove plural if < 2. +((${d/ */} == 1)) && d=${d/s/} +((${h/ */} == 1)) && h=${h/s/} +((${m/ */} == 1)) && m=${m/s/} + +# Hide empty fields. +((${d/ */} == 0)) && unset d +((${h/ */} == 0)) && unset h +((${m/ */} == 0)) && unset m + +uptime=${d:+$d, }${h:+$h, }$m +uptime=${uptime%', '} +uptime=${uptime:-$seconds seconds} + +sketchybar --set "$NAME" label="up $uptime"