* 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 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 -- Dustin Kirkland <kirkland@ubuntu.com> Tue, 21 Feb 2012 23:22:38 -0600

View file

@ -34,22 +34,27 @@ for i in "${BYOBU_PREFIX}/share/$PKG/status/status" "${BYOBU_PREFIX}/share/$PKG/
[ -r "$i" ] && . "$i" [ -r "$i" ] && . "$i"
done done
# Reload profile, if necessary case "$BYOBU_BACKEND" in
if [ -e "/var/run/screen/S-$USER/$PKG.reload-required" ] || [ -e "$BYOBU_RUN_DIR/reload-required" ]; then screen)
if [ "$BYOBU_BACKEND" = "screen" ] && [ -r "$BYOBU_CONFIG_DIR/profile" ]; then # Reload profile, if necessary
# If the forced janitorial steps succeed, try a profile reload if [ -e "/var/run/screen/S-$USER/$PKG.reload-required" ] || [ -e "$BYOBU_RUN_DIR/reload-required" ]; then
byobu-janitor --force && screen -X at 0 source "$BYOBU_CONFIG_DIR/profile" >/dev/null 2>&1 if [ -r "$BYOBU_CONFIG_DIR/profile" ]; then
fi # If the forced janitorial steps succeed, try a profile reload
fi byobu-janitor --force && screen -X at 0 source "$BYOBU_CONFIG_DIR/profile" >/dev/null 2>&1
fi
# Do first-run procedures, if necessary fi
if [ -n "$TMUX" ]; then ;;
if [ ! -e "$BYOBU_RUN_DIR/${TMUX#*,}" ]; then tmux)
# Clear initial window name # Do first-run procedures, if necessary
tmux rename-window "" if [ -n "$TMUX" ]; then
touch "$BYOBU_RUN_DIR/${TMUX#*,}" if [ ! -e "$BYOBU_RUN_DIR/${TMUX#*,}" ]; then
fi # Clear initial window name
fi tmux rename-window ""
touch "$BYOBU_RUN_DIR/${TMUX#*,}"
fi
fi
;;
esac
# Get the current timestamp # Get the current timestamp
get_now; NOW=${_RET} get_now; NOW=${_RET}
@ -77,10 +82,16 @@ get_status() {
find_script "$function" && . "${_RET}" find_script "$function" && . "${_RET}"
# Update cache now, if necessary # Update cache now, if necessary
if [ $NOW -ge $expiry ] || [ "$lastrun" = "0" ]; then if [ $NOW -ge $expiry ] || [ "$lastrun" = "0" ]; then
"__$function" > "$cachepath" "__$function" > "$cachepath".new
printf "%s" "$NOW" > "$lastpath"
fi 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" IFS= read line < "$cachepath"; printf "%s" "$line"
fi fi
} }

View file

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

View file

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

View file

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

View file

@ -44,6 +44,7 @@ __disk() {
g*|G*) unit="$ICON_GB" ;; g*|G*) unit="$ICON_GB" ;;
t*|T*) unit="$ICON_TB" ;; t*|T*) unit="$ICON_TB" ;;
esac 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" "$size"; color -; color M W; printf "%s" "$unit"; color -;
color b M W; printf "%s" "$pct"; color -; color M W; printf "%s" "$PCT"; 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" unit="kB/s"
fi fi
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 -- color b M W; printf "%s%s" "$symbol" "$rate"; color -; color M W; printf "%s" "$unit"; color --
done done
} }

View file

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

View file

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

View file

@ -24,6 +24,7 @@ __entropy_detail() {
__entropy() { __entropy() {
local e=$(cat /proc/sys/kernel/random/entropy_avail) local e=$(cat /proc/sys/kernel/random/entropy_avail)
[ -n "$e" ] || return
color K Y; printf "e%s" "$e"; color -- 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 for i in $FAN /sys/class/hwmon/*/*/fan1_input /sys/class/hwmon/*/device/hwmon/*/fan1_input; do
[ -f "$i" ] || continue [ -f "$i" ] || continue
read speed < "$i" 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 -- color bold1; printf "%s" "$speed"; color -; color none; printf "rpm"; color --
return 0 return 0
fi fi
@ -43,7 +43,7 @@ __fan_speed() {
read line < /proc/i8k read line < /proc/i8k
set -- $line set -- $line
for speed in $7 $8; do 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?), # I8K_FAN_MULT defaults to 30 (buggy BIOS workaround?),
# use `modprobe i8k fan_mult=1` to disable if unneeded, # use `modprobe i8k fan_mult=1` to disable if unneeded,
# resulting in nonsensical speeds # resulting in nonsensical speeds

View file

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

View file

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

View file

@ -53,6 +53,7 @@ __memory() {
else else
unit="$ICON_KB" unit="$ICON_KB"
fi 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 -- 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 fi
;; ;;
esac esac
[ -n "$rate" ] || continue
color b m w; printf "%s%s" "$symbol" "$rate"; color -; color m w; printf "%s" "$unit"; color -- color b m w; printf "%s%s" "$symbol" "$rate"; color -; color m w; printf "%s" "$unit"; color --
fi fi
done done

View file

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

View file

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

View file

@ -91,6 +91,7 @@ __rcs_cost() {
return return
fi fi
[ -n "$total_cost" ] || return
color K G; printf "R\$%s"; color -; color b K G; printf "%s" "$total_cost"; color -- 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" mem="$mem"
unit="$ICON_KB" unit="$ICON_KB"
fi 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%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 -- color b G W; printf "%s" "$f"; color -; color G W; printf "%s" "$PCT"; color --
} }

View file

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

View file

@ -40,6 +40,7 @@ __wifi_quality() {
if [ -z "$quality" ] || [ "$quality" = "0" ]; then if [ -z "$quality" ] || [ "$quality" = "0" ]; then
quality="0" quality="0"
fi fi
[ -n "$quality" ] || return
[ "$quality" = "0" ] && 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 -- 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 --
} }