aboutsummaryrefslogtreecommitdiffstats
path: root/config/hypr/scripts/UptimeNixOS.sh
diff options
context:
space:
mode:
authorJa.KooLit <jimmielovejay@gmail.com>2024-05-10 17:21:12 +0900
committerGitHub <noreply@github.com>2024-05-10 17:21:12 +0900
commitd44b77d2ebc248fd8e94c5bd2e5a3532c9a9fb71 (patch)
treeba7419e774eed9bf687545d257d6709d1ed02ba3 /config/hypr/scripts/UptimeNixOS.sh
parente742b39139813b04706c30f097e0d9829ea7c776 (diff)
parent4cd64ff0b907f8d8d6503bcb7c858ca25494d1cb (diff)
Merge pull request #253 from JohnRTitor/patch-hyprlock
hyprlock: add alternative script for NixOS, if `uptime -p` fails
Diffstat (limited to 'config/hypr/scripts/UptimeNixOS.sh')
-rw-r--r--config/hypr/scripts/UptimeNixOS.sh33
1 files changed, 33 insertions, 0 deletions
diff --git a/config/hypr/scripts/UptimeNixOS.sh b/config/hypr/scripts/UptimeNixOS.sh
new file mode 100644
index 00000000..654ae2c8
--- /dev/null
+++ b/config/hypr/scripts/UptimeNixOS.sh
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+# Script parses /proc/uptime to get the system uptime
+# and prints it in a human-readable format
+# This is a workaround for system where `uptime` command is taken from coreutils
+# where `uptime -p` is not supported
+
+if [[ -r /proc/uptime ]]; then
+ s=$(< /proc/uptime)
+ s=${s/.*}
+else
+ echo "Error UptimeNixOS.sh: Uptime could not be determined." >&2
+ exit 1
+fi
+
+d="$((s / 60 / 60 / 24)) days"
+h="$((s / 60 / 60 % 24)) hours"
+m="$((s / 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:-$s seconds}
+
+echo "up $uptime"
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage