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
=== modified file 'usr/lib/byobu/uptime'
--- usr/lib/byobu/uptime 2016-04-07 22:07:52 +0000
+++ usr/lib/byobu/uptime 2016-05-28 14:13:09 +0000
@@ -30,18 +30,25 @@
30 if [ -r /proc/uptime ]; then30 if [ -r /proc/uptime ]; then
31 read u idle < /proc/uptime31 read u idle < /proc/uptime
32 u=${u%.*}32 u=${u%.*}
33 elif [ -x /usr/sbin/sysctl ]; then
34 u=$(/usr/sbin/sysctl -n kern.boottime | cut -f4 -d' ' | cut -d',' -f1)
35 u=$(($(date +%s) - $u))
36 fi
37
38 if [ "$u" ]; then
33 if [ "$u" -gt 86400 ]; then39 if [ "$u" -gt 86400 ]; then
34 str="$(($u / 86400))d$((($u % 86400) / 3600))h"40 str="$(($u / 86400))d$((($u % 86400) / 3600))h"
35 elif [ "$u" -gt 3600 ]; then41 elif [ "$u" -gt 3600 ]; then
36 str="$(($u / 3600))h$((($u % 3600) / 60))m"42 str="$(($u / 3600))h$((($u % 3600) / 60))m"
37 elif [ "$u" -gt 60 ]; then43 elif [ "$u" -gt 60 ]; then
38 str="$(($u / 60))m"44 str="$(($u / 60))m"
39 else45 else
40 str="${u}s"46 str="${u}s"
41 fi47 fi
42 else48 else
43 str=$(uptime | sed -e "s/.* up *//" -e "s/ *days, */d/" -e "s/:/h/" -e "s/,.*/m/")49 str=$(uptime | sed -e "s/.* up *//" -e "s/ *days, */d/" -e "s/:/h/" -e "s/,.*/m/")
44 fi50 fi
51
45 [ -n "$str" ] || return52 [ -n "$str" ] || return
46 color w b; printf "%s" "${str}"; color --53 color w b; printf "%s" "${str}"; color --
47}54}

Subscribers

People subscribed via source and target branches