* usr/bin/byobu-status, usr/lib/byobu/battery, usr/lib/byobu/cpu_freq,

usr/lib/byobu/custom, usr/lib/byobu/disk, usr/lib/byobu/disk_io,
  usr/lib/byobu/distro, usr/lib/byobu/ec2_cost, usr/lib/byobu/entropy,
  usr/lib/byobu/fan_speed, usr/lib/byobu/hostname,
  usr/lib/byobu/load_average, usr/lib/byobu/memory,
  usr/lib/byobu/network, usr/lib/byobu/processes, usr/lib/byobu/raid,
  usr/lib/byobu/rcs_cost, usr/lib/byobu/swap, usr/lib/byobu/uptime,
  usr/lib/byobu/wifi_quality:
  - help ensure that a status is printed
  - this fixes byobu status on some slower systems
  - use the last cached status, if the current one doesn't return
This commit is contained in:
Dustin Kirkland 2012-02-23 08:02:53 -06:00
commit b56a6cff31
21 changed files with 63 additions and 26 deletions

12
debian/changelog vendored
View file

@ -1,6 +1,16 @@
byobu (5.14) unreleased; urgency=low
* UNRELEASED
* usr/bin/byobu-status, usr/lib/byobu/battery, usr/lib/byobu/cpu_freq,
usr/lib/byobu/custom, usr/lib/byobu/disk, usr/lib/byobu/disk_io,
usr/lib/byobu/distro, usr/lib/byobu/ec2_cost, usr/lib/byobu/entropy,
usr/lib/byobu/fan_speed, usr/lib/byobu/hostname,
usr/lib/byobu/load_average, usr/lib/byobu/memory,
usr/lib/byobu/network, usr/lib/byobu/processes, usr/lib/byobu/raid,
usr/lib/byobu/rcs_cost, usr/lib/byobu/swap, usr/lib/byobu/uptime,
usr/lib/byobu/wifi_quality:
- help ensure that a status is printed
- this fixes byobu status on some slower systems
- use the last cached status, if the current one doesn't return
-- Dustin Kirkland <kirkland@ubuntu.com> Tue, 21 Feb 2012 23:22:38 -0600

View file

@ -34,14 +34,17 @@ for i in "${BYOBU_PREFIX}/share/$PKG/status/status" "${BYOBU_PREFIX}/share/$PKG/
[ -r "$i" ] && . "$i"
done
case "$BYOBU_BACKEND" in
screen)
# Reload profile, if necessary
if [ -e "/var/run/screen/S-$USER/$PKG.reload-required" ] || [ -e "$BYOBU_RUN_DIR/reload-required" ]; then
if [ "$BYOBU_BACKEND" = "screen" ] && [ -r "$BYOBU_CONFIG_DIR/profile" ]; then
if [ -r "$BYOBU_CONFIG_DIR/profile" ]; then
# If the forced janitorial steps succeed, try a profile reload
byobu-janitor --force && screen -X at 0 source "$BYOBU_CONFIG_DIR/profile" >/dev/null 2>&1
fi
fi
;;
tmux)
# Do first-run procedures, if necessary
if [ -n "$TMUX" ]; then
if [ ! -e "$BYOBU_RUN_DIR/${TMUX#*,}" ]; then
@ -50,6 +53,8 @@ if [ -n "$TMUX" ]; then
touch "$BYOBU_RUN_DIR/${TMUX#*,}"
fi
fi
;;
esac
# Get the current timestamp
get_now; NOW=${_RET}
@ -77,10 +82,16 @@ get_status() {
find_script "$function" && . "${_RET}"
# Update cache now, if necessary
if [ $NOW -ge $expiry ] || [ "$lastrun" = "0" ]; then
"__$function" > "$cachepath"
printf "%s" "$NOW" > "$lastpath"
"__$function" > "$cachepath".new
fi
if [ -s "$cachepath" ]; then
# Check if we have data in the cache
if [ -s "$cachepath".new ]; then
# Looks like we have an updated cache, use it
mv -f "$cachepath".new "$cachepath"
printf "%s" "$NOW" > "$lastpath"
IFS= read line < "$cachepath"; printf "%s" "$line"
elif [ -s "$cachepath" ]; then
# New cache is empty, but we have data from our last run, use it
IFS= read line < "$cachepath"; printf "%s" "$line"
fi
}

View file

@ -88,6 +88,7 @@ __battery() {
charged|Unknown|Full) sign="="; percent="" ;;
*) sign="$state" ;;
esac
[ -n "$percent" ] || return
color $bcolor; printf "%s" "$percent"; color -; color $color; printf "%s" "$sign"; color --
fi
}

View file

@ -39,6 +39,7 @@ __cpu_freq() {
freq=$(printf "%s %s" "$freq" "$count" | awk '{printf "%01.1f\n", $1/$2/1000}')
fi
fi
[ -n "$freq" ] || return
color b c W; printf "%s" "$freq"; color -; color c W; printf "%s" "$ICON_GHz"; color --
}

View file

@ -53,6 +53,7 @@ __custom() {
;;
esac
done
[ -n "$output" ] || return
printf "$output" | $BYOBU_SED ':a;N;$!ba;s/\n//g'
}

View file

@ -44,6 +44,7 @@ __disk() {
g*|G*) unit="$ICON_GB" ;;
t*|T*) unit="$ICON_TB" ;;
esac
[ -n "$size" ] || return
color b M W; printf "%s" "$size"; color -; color M W; printf "%s" "$unit"; color -;
color b M W; printf "%s" "$pct"; color -; color M W; printf "%s" "$PCT"; color --;
}

View file

@ -90,7 +90,8 @@ __disk_io() {
unit="kB/s"
fi
fi
[ "$rate" != "0" ] || continue
[ -z "$rate" ] && continue
[ "$rate" = "0" ] && continue
color b M W; printf "%s%s" "$symbol" "$rate"; color -; color M W; printf "%s" "$unit"; color --
done
}

View file

@ -61,6 +61,7 @@ __distro() {
else
DISTRO="Byobu"
fi
[ -n "$DISTRO" ] || return
color bold2; printf "%s" "$DISTRO"; color --
}

View file

@ -118,6 +118,7 @@ __ec2_cost() {
echo "================================================"
return
fi
[ -n "$total_cost" ] || return
color K G; printf "A\$"; color -; color b K G; printf "%s" "$total_cost"; color --
}

View file

@ -24,6 +24,7 @@ __entropy_detail() {
__entropy() {
local e=$(cat /proc/sys/kernel/random/entropy_avail)
[ -n "$e" ] || return
color K Y; printf "e%s" "$e"; color --
}

View file

@ -31,7 +31,7 @@ __fan_speed() {
for i in $FAN /sys/class/hwmon/*/*/fan1_input /sys/class/hwmon/*/device/hwmon/*/fan1_input; do
[ -f "$i" ] || continue
read speed < "$i"
if [ "$speed" -gt 0 ]; then
if [ -n "$speed" ] && [ "$speed" -gt 0 ]; then
color bold1; printf "%s" "$speed"; color -; color none; printf "rpm"; color --
return 0
fi
@ -43,7 +43,7 @@ __fan_speed() {
read line < /proc/i8k
set -- $line
for speed in $7 $8; do
if [ "$speed" -gt 0 ]; then
if [ -n "$speed" ] && [ "$speed" -gt 0 ]; then
# I8K_FAN_MULT defaults to 30 (buggy BIOS workaround?),
# use `modprobe i8k fan_mult=1` to disable if unneeded,
# resulting in nonsensical speeds

View file

@ -34,6 +34,7 @@ __hostname() {
else
h=$(hostname -s 2>/dev/null || hostname)
fi
[ -n "$h" ] || return
color bold2; printf "%s" "$h"; color --
}

View file

@ -25,6 +25,7 @@ __load_average_detail() {
__load_average() {
read one five fifteen other < /proc/loadavg
[ -n "$one" ] || return
color Y k; printf "$one"; color --
}

View file

@ -53,6 +53,7 @@ __memory() {
else
unit="$ICON_KB"
fi
[ -n "$total" ] || return
color b g W; printf "%s" "$total"; color -; color g W; printf "%s" "$unit"; color -; color b g W; printf "%s" "$f"; color -; color g W; printf "%s" "$PCT"; color --
}

View file

@ -87,6 +87,7 @@ __network() {
fi
;;
esac
[ -n "$rate" ] || continue
color b m w; printf "%s%s" "$symbol" "$rate"; color -; color m w; printf "%s" "$unit"; color --
fi
done

View file

@ -25,6 +25,7 @@ __processes_detail() {
__processes() {
local count=$(ls -d /proc/[0-9]* 2>/dev/null| wc -l)
[ -n "$count" ] || return
color b y w; printf "%s" "$count"; color -; color y w; printf "&"; color --
}

View file

@ -36,9 +36,8 @@ __raid() {
msg="$msg,$p";;
esac
done < /proc/mdstat
if [ -n "$msg" ]; then
[ -n "$msg" ] || return
color B w r; printf "%s" "$msg"; color --
fi
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -91,6 +91,7 @@ __rcs_cost() {
return
fi
[ -n "$total_cost" ] || return
color K G; printf "R\$%s"; color -; color b K G; printf "%s" "$total_cost"; color --
}

View file

@ -50,6 +50,7 @@ __swap() {
mem="$mem"
unit="$ICON_KB"
fi
[ -n "$mem" ] || return
color b G W; printf "s%s" "$mem"; color -; color G W; printf "%s" "$unit"; color -;
color b G W; printf "%s" "$f"; color -; color G W; printf "%s" "$PCT"; color --
}

View file

@ -38,6 +38,7 @@ __uptime() {
else
str="${u}s"
fi
[ -n "$str" ] || return
color w b; printf "%s" "${str}"; color --
}

View file

@ -40,6 +40,7 @@ __wifi_quality() {
if [ -z "$quality" ] || [ "$quality" = "0" ]; then
quality="0"
fi
[ -n "$quality" ] || return
[ "$quality" = "0" ] && return
printf "${ICON_WIFI}"; color b C k; printf "%s" "$bitrate"; color -; color C k; printf "%s" "$ICON_MBPS"; color -; color b C k; printf "%s" "$quality"; color -; color C k; printf "%s" "$PCT"; color --
}