mirror of
https://github.com/Ahwxorg/nixos-config.git
synced 2026-03-19 07:40:30 +01:00
feat: adds uptime plugin to sketchybar
This commit is contained in:
parent
e742458886
commit
4eb98175c0
1 changed files with 26 additions and 0 deletions
26
modules/home/sketchybar/plugins/uptime.sh
Normal file
26
modules/home/sketchybar/plugins/uptime.sh
Normal file
|
|
@ -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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue