Merge lp:~kevin.mark/byobu/fix-uptime-osx into lp:byobu

Proposed by Kevin Mark
Status: Merged
Merged at revision: 2497
Proposed branch: lp:~kevin.mark/byobu/fix-uptime-osx
Merge into: lp:byobu
Diff against target: 33 lines (+11/-4)
1 file modified
usr/lib/byobu/uptime (+11/-4)
To merge this branch: bzr merge lp:~kevin.mark/byobu/fix-uptime-osx
Reviewer Review Type Date Requested Status
Dustin Kirkland  Pending
Review via email: mp+295993@code.launchpad.net

Commit message

Fixes the uptime status notification on OS X.

Description of the change

This fixes the uptime status notification on OS X. Previously it would fall back to parsing `uptime` and that would give bad output.

There are a few different ways I could've detected the OS (like what's done in logo) but I think checking for /usr/sbin/sysctl is probably sufficient enough here. I suppose I also could've "fixed" the sed line but I assume it's working somewhere else and I'd have to branch for that anyway.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'usr/lib/byobu/uptime'
2--- usr/lib/byobu/uptime 2016-04-07 22:07:52 +0000
3+++ usr/lib/byobu/uptime 2016-05-28 14:13:09 +0000
4@@ -30,18 +30,25 @@
5 if [ -r /proc/uptime ]; then
6 read u idle < /proc/uptime
7 u=${u%.*}
8+ elif [ -x /usr/sbin/sysctl ]; then
9+ u=$(/usr/sbin/sysctl -n kern.boottime | cut -f4 -d' ' | cut -d',' -f1)
10+ u=$(($(date +%s) - $u))
11+ fi
12+
13+ if [ "$u" ]; then
14 if [ "$u" -gt 86400 ]; then
15- str="$(($u / 86400))d$((($u % 86400) / 3600))h"
16+ str="$(($u / 86400))d$((($u % 86400) / 3600))h"
17 elif [ "$u" -gt 3600 ]; then
18- str="$(($u / 3600))h$((($u % 3600) / 60))m"
19+ str="$(($u / 3600))h$((($u % 3600) / 60))m"
20 elif [ "$u" -gt 60 ]; then
21- str="$(($u / 60))m"
22+ str="$(($u / 60))m"
23 else
24- str="${u}s"
25+ str="${u}s"
26 fi
27 else
28 str=$(uptime | sed -e "s/.* up *//" -e "s/ *days, */d/" -e "s/:/h/" -e "s/,.*/m/")
29 fi
30+
31 [ -n "$str" ] || return
32 color w b; printf "%s" "${str}"; color --
33 }

Subscribers

People subscribed via source and target branches