aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/up
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2019-10-16 13:56:23 +0200
committerPatrick Spek <p.spek@tyil.nl>2019-10-16 13:56:23 +0200
commitf6ecdfb40fcb63f89961352362c2b3a3d00edf92 (patch)
treeafb38c0a2d3c55797124f118901c82f24a5cfd5a /.local/bin/up
parent9dfa9e1ca2526f98e82ef7002abf21adfaecdace (diff)
Rewrite up utility to be POSIX compliant
Diffstat (limited to '.local/bin/up')
-rwxr-xr-x.local/bin/up20
1 files changed, 11 insertions, 9 deletions
diff --git a/.local/bin/up b/.local/bin/up
index f771781..cdceaa2 100755
--- a/.local/bin/up
+++ b/.local/bin/up
@@ -1,12 +1,14 @@
-#!/usr/bin/env bash
+#! /usr/bin/env sh
-uptime=$(</proc/uptime)
-uptime=${uptime%%.*}
+main()
+{
+ seconds=$(awk -F. '{print $1}' < /proc/uptime)
-seconds=$(( uptime%60 ))
-minutes=$(( uptime/60%60 ))
-hours=$(( uptime/60/60%24 ))
-days=$(( uptime/60/60/24 ))
-
-echo "${days}d ${hours}h ${minutes}m ${seconds}s"
+ printf "%dd %02dh %02dm %02ds\n" \
+ "$(( seconds / 60 / 60 / 24 ))" \
+ "$(( seconds / 60 / 60 % 24 ))" \
+ "$(( seconds / 60 % 60 ))" \
+ "$(( seconds % 60 ))"
+}
+main "$@"