mirror of
https://github.com/adi1090x/rofi.git
synced 2024-11-21 21:58:21 -05:00
remove awk
This commit is contained in:
parent
2ccb022c95
commit
1d0689cb33
@ -1,21 +1,32 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
uptime_seconds=$(awk '{print $1}' /proc/uptime)
|
uptime_seconds=$(cat /proc/uptime | sed 's/^\([0-9]\+\)\..*/\1/')
|
||||||
echo -n $(awk -v UP="$uptime_seconds" '
|
|
||||||
BEGIN {
|
# Format the uptime
|
||||||
days = int(UP / 86400);
|
days=$(( uptime_seconds / 86400 ))
|
||||||
hours = int((UP % 86400) / 3600);
|
hours=$(( (uptime_seconds % 86400) / 3600 ))
|
||||||
minutes = int((UP % 3600) / 60);
|
minutes=$(( (uptime_seconds % 3600) / 60 ))
|
||||||
seconds = int(UP % 60);
|
|
||||||
if (days > 0) {
|
# Helper function for pluralization
|
||||||
if (days == 1) {
|
pluralize() {
|
||||||
printf "1 day, %d hours, %d minutes\n", hours, minutes;
|
local value=$1
|
||||||
} else {
|
local singular=$2
|
||||||
printf "%d days, %d hours, %d minutes\n", days, hours, minutes;
|
local plural=$3
|
||||||
|
if [ "$value" -eq 1 ]; then
|
||||||
|
echo "$value $singular"
|
||||||
|
else
|
||||||
|
echo "$value $plural"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
} else if (hours > 0) {
|
|
||||||
printf "%d hours, %d minutes\n", hours, minutes;
|
# Construct the uptime string
|
||||||
} else {
|
if [ "$days" -gt 0 ]; then
|
||||||
printf "%d minutes\n", minutes;
|
uptime="$(pluralize $days day days), $(pluralize $hours hour hours), $(pluralize $minutes minute minutes)"
|
||||||
}
|
elif [ "$hours" -gt 0 ]; then
|
||||||
}')
|
uptime="$(pluralize $hours hour hours), $(pluralize $minutes minute minutes)"
|
||||||
|
else
|
||||||
|
uptime="$(pluralize $minutes minute minutes)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$uptime"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user