Merge pull request #231 from dylanaraps/uptime_fixes
OSX and BSD uptime fixes.
This commit is contained in:
commit
854f9e505e
1 changed files with 27 additions and 20 deletions
43
neofetch
43
neofetch
|
@ -586,30 +586,37 @@ getuptime () {
|
|||
uptime=$((now - boot))
|
||||
|
||||
# Convert uptime to days/hours/mins
|
||||
mins=$((uptime / 60%60))
|
||||
minutes=$((uptime / 60%60))
|
||||
hours=$((uptime / 3600%24))
|
||||
days=$((uptime / 86400))
|
||||
|
||||
# Format the output like Linux's "uptime -p" cmd.
|
||||
if [ "$mins" == 1 ]; then
|
||||
uptime="$mins minute"
|
||||
elif [ "$mins" != 0 ]; then
|
||||
uptime="$mins minutes"
|
||||
fi
|
||||
case "$minutes" in
|
||||
1) minutes="1 minute" ;;
|
||||
0) unset minutes ;;
|
||||
*) minutes="$minutes minutes" ;;
|
||||
esac
|
||||
|
||||
if [ "$hours" == 1 ]; then
|
||||
uptime="$hours hour, $uptime"
|
||||
elif [ "$mins" != 0 ]; then
|
||||
uptime="$hours hours, $uptime"
|
||||
fi
|
||||
case "$hours" in
|
||||
1) hours="1 hour" ;;
|
||||
0) unset hours ;;
|
||||
*) hours="$hours hours" ;;
|
||||
esac
|
||||
|
||||
if [ "$days" == 1 ]; then
|
||||
uptime="$days day, $uptime"
|
||||
elif [ "$days" != 0 ]; then
|
||||
uptime="$days days, $uptime"
|
||||
fi
|
||||
case "$days" in
|
||||
1) days="1 day" ;;
|
||||
0) unset days ;;
|
||||
*) days="$days days" ;;
|
||||
esac
|
||||
|
||||
uptime="up $uptime"
|
||||
[ ! -z "$hours" ] && \
|
||||
[ ! -z "$minutes" ] && \
|
||||
hours+=","
|
||||
|
||||
[ ! -z "$days" ] && \
|
||||
[ ! -z "$hours" ] && \
|
||||
days+=","
|
||||
|
||||
uptime="up $days $hours $minutes"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
Loading…
Reference in a new issue