mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-23 06:36:17 -07:00
lots more performance improvements to status scripts:
* battery: from: 0m11.056s, 0m0.270s, 0m0.810s to__: 0m0.873s, 0m0.370s, 0m0.260s * cpu_temp: from: 0m2.727s, 0m0.200s, 0m0.340s to__: 0m1.049s, 0m0.220s, 0m0.450s * date: from: 0m2.675s, 0m0.110s, 0m0.280s to__: 0m1.413s, 0m0.100s, 0m0.180s * disk: from: 0m7.462s, 0m0.200s, 0m0.360s to__: 0m2.000s, 0m0.150s, 0m0.280s note: output removed a trailing space * fan_speed: from: 0m3.671s, 0m0.150s, 0m0.230s to__: 0m0.677s, 0m0.180s, 0m0.220s * ip_address: from: 0m3.764s, 0m0.220s, 0m0.400s to__: 0m3.314s, 0m0.220s, 0m0.420s notes:' * removed 1 fork in ipv4 route, 2 forks in ipv6 route results above are with IPV6="". I do not have an explanation for the increase in sys time on this. * mem_available: from: 0m4.393s, 0m0.250s, 0m0.380s to__: 0m0.304s, 0m0.150s, 0m0.150s * mem_used: from: 0m1.997s, 0m0.040s, 0m0.260s to__: 0m0.308s, 0m0.130s, 0m0.160s notes: * there is a 2 to 3x growth in user cpu time here. that is primarily due to 'read'ing /proc/meminfo however, coupled with the reduction in sys time, we're about even and wallclock is ~ 1/6th. * raid: from: 0m2.842s, 0m0.130s, 0m0.390s to__: 0m0.084s, 0m0.070s, 0m0.010s notes: * if /proc/mdstat was large, 'read'ing it could be slower than using grep. this result is on my laptop where it is empty * release: from: 0m0.126s, 0m0.050s, 0m0.060s to__: 0m0.158s, 0m0.050s, 0m0.100s notes: * there is no real difference if DISTRO is set. if DISTRO is not set, it looks more like: from: 0m3.506s, 0m0.140s, 0m0.330s to__: 0m0.158s, 0m0.080s, 0m0.070s * swap: from: 0m7.071s, 0m0.150s, 0m0.360s to__: 0m0.473s, 0m0.280s, 0m0.150s notes: * This is hand-hacked a bit, because on my system I have swap, but the percentage used was '0' in both cases. So, I commented out the line that returns/exits if 'f == 0'. * updates_available: very minimal changes, only 'which' -> 'command -v' and 2 removals of 'tail -n 1'
This commit is contained in:
parent
5b6dcfbf54
commit
ac688259c7
12 changed files with 272 additions and 164 deletions
|
@ -21,14 +21,6 @@
|
||||||
PKG="byobu"
|
PKG="byobu"
|
||||||
color 2>/dev/null || color() { true; }
|
color 2>/dev/null || color() { true; }
|
||||||
|
|
||||||
search () {
|
|
||||||
local str expr
|
|
||||||
str="$1"
|
|
||||||
expr="$2"
|
|
||||||
echo "$str" | sed -n "s/${expr}/\1/p"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if [ "$1" = "--detail" ]; then
|
if [ "$1" = "--detail" ]; then
|
||||||
for bat in /proc/acpi/battery/*; do
|
for bat in /proc/acpi/battery/*; do
|
||||||
cat "$bat/info"
|
cat "$bat/info"
|
||||||
|
@ -37,18 +29,35 @@ if [ "$1" = "--detail" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for bat in $BATTERY /proc/acpi/battery/*; do
|
battery_info() {
|
||||||
|
local bat line present sign state percent full rem color bcolor
|
||||||
|
for bat in $BATTERY /proc/acpi/battery/*; do
|
||||||
|
[ -f "$bat/info" ] || continue
|
||||||
|
|
||||||
|
present=""; full=""; rem=""; state=""
|
||||||
|
while read line; do
|
||||||
|
set -- ${line}
|
||||||
|
case "$line" in
|
||||||
|
present:*)
|
||||||
# make sure that this battery is present
|
# make sure that this battery is present
|
||||||
infofile=$(cat "$bat/info")
|
[ "$2" = "no" ] && continue 2
|
||||||
present=$(search "$infofile" "present: *\(.*\)")
|
present="$2";;
|
||||||
[ "${present}" = "no" ] && continue
|
last\ full\ capacity:*) full="$4";;
|
||||||
|
esac
|
||||||
|
[ -n "$present" -a -n "$full" ] && break
|
||||||
|
done < "${bat}/info"
|
||||||
|
|
||||||
# obtain full and remaining battery values
|
while read line; do
|
||||||
statefile=$(cat "$bat/state")
|
set -- ${line}
|
||||||
full=$(search "$infofile" "last full capacity: *\(.*\) m[AW]h")
|
case "$line" in
|
||||||
rem=$(search "$statefile" "remaining capacity: *\(.*\) m[AW]h")
|
remaining\ capacity:*) rem="$3";;
|
||||||
|
charging\ state:*) state="$3";;
|
||||||
|
esac
|
||||||
|
[ -n "$rem" -a -n "$state" ] && break
|
||||||
|
done < "$bat/state"
|
||||||
|
|
||||||
|
percent=$(((100*$rem)/$full))
|
||||||
|
|
||||||
percent=$( echo "$rem" "$full" | awk '{printf "%.0f", 100*$1/$2}')
|
|
||||||
if [ "$percent" -lt 33 ]; then
|
if [ "$percent" -lt 33 ]; then
|
||||||
color="R k"
|
color="R k"
|
||||||
bcolor="b R k"
|
bcolor="b R k"
|
||||||
|
@ -61,22 +70,15 @@ for bat in $BATTERY /proc/acpi/battery/*; do
|
||||||
fi
|
fi
|
||||||
percent="$percent%"
|
percent="$percent%"
|
||||||
|
|
||||||
state=$(search "$statefile" "charging state: *\(.*\)")
|
|
||||||
case $state in
|
case $state in
|
||||||
charging)
|
charging) sign="+" ;;
|
||||||
sign="+"
|
discharging) sign="-" ;;
|
||||||
;;
|
charged) sign="="; percent="" ;;
|
||||||
discharging)
|
*) sign="$state" ;;
|
||||||
sign="-"
|
|
||||||
;;
|
|
||||||
charged)
|
|
||||||
sign="="
|
|
||||||
percent=
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
sign="$state"
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
color $bcolor; printf "%s" "$percent"; color -; color $color; printf "|%s|" "$sign"; color --
|
color $bcolor; printf "%s" "$percent"; color -; color $color; printf "|%s|" "$sign"; color --
|
||||||
break
|
break
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
battery_info "$@"
|
||||||
|
|
|
@ -36,7 +36,7 @@ fi
|
||||||
for i in $MONITORED_TEMP /sys/class/hwmon/hwmon*/temp*_input /proc/acpi/ibm/thermal $DIR/*/temperature; do
|
for i in $MONITORED_TEMP /sys/class/hwmon/hwmon*/temp*_input /proc/acpi/ibm/thermal $DIR/*/temperature; do
|
||||||
case "$i" in
|
case "$i" in
|
||||||
*temp*_input)
|
*temp*_input)
|
||||||
[ -s "$i" ] && t=$(awk '{printf "%0.f",$1/1000}' "$i")
|
[ -s "$i" ] && read t < "$i" && t=$(($t/1000))
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
[ -s "$i" ] && t=$(sed -e "s/^[^0-9]\+//" -e "s/\s.*$//" "$i")
|
[ -s "$i" ] && t=$(sed -e "s/^[^0-9]\+//" -e "s/\s.*$//" "$i")
|
||||||
|
@ -45,7 +45,7 @@ for i in $MONITORED_TEMP /sys/class/hwmon/hwmon*/temp*_input /proc/acpi/ibm/ther
|
||||||
if [ -n "$t" ]; then
|
if [ -n "$t" ]; then
|
||||||
unit="$ICON_C"
|
unit="$ICON_C"
|
||||||
if [ "$TEMP" = "F" ]; then
|
if [ "$TEMP" = "F" ]; then
|
||||||
t=$(echo "$t" | awk '{printf "%.0f", $1 *9/5 + 32}')
|
t=$(($t*9/5 + 32))
|
||||||
unit="$ICON_F"
|
unit="$ICON_F"
|
||||||
fi
|
fi
|
||||||
color b k Y; printf "%s" "$t"; color -; color k Y; printf "%s%s" "$ICON" "$unit"; color --
|
color b k Y; printf "%s" "$t"; color -; color k Y; printf "%s%s" "$ICON" "$unit"; color --
|
||||||
|
|
|
@ -25,8 +25,10 @@ case "$1" in
|
||||||
date +%Y-%m-%d
|
date +%Y-%m-%d
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
msg="$(echo SGFwcHkgQmlydGhkYXkgU2NyZWVuIC0tIGh0dHA6Ly9iaXQubHkvc2NyZWVuLWJkYXkK | base64 -di)"
|
bd=$(date "+%m%d")
|
||||||
[ "$(date +%d)" = "20" ] && [ "$(date +%m)" = "03" ] && screen -X -S "byobu" at "*" echo "[$msg]"
|
[ "$bd" = "0320" ] &&
|
||||||
|
msg="$(echo SGFwcHkgQmlydGhkYXkgU2NyZWVuIC0tIGh0dHA6Ly9iaXQubHkvc2NyZWVuLWJkYXkK | base64 -di)" &&
|
||||||
|
screen -X -S "byobu" at "*" echo "[$msg]"
|
||||||
printf "\005Y-\005m-\005d "
|
printf "\005Y-\005m-\005d "
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -28,9 +28,26 @@ fi
|
||||||
# Default to /, but let users override
|
# Default to /, but let users override
|
||||||
[ -z "$MONITORED_DISK" ] && MP="/" || MP="$MONITORED_DISK"
|
[ -z "$MONITORED_DISK" ] && MP="/" || MP="$MONITORED_DISK"
|
||||||
case $MP in
|
case $MP in
|
||||||
/dev/*) MP=$(grep "$MP" /proc/mounts | awk '{print $2}') ;;
|
/dev/*) MP=$(awk '$1 == m { print $2; exit(0); }' "m=$MP" /proc/mounts);;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
disk=$(df -h -P "$MP" 2>/dev/null || df -h "$MP")
|
get_size_pct() {
|
||||||
disk=$(echo "$disk" | tail -n 1 | awk '{print $2 " " $5}' | sed "s/\([^0-9\. ]\)/ \1/g" | awk '{printf "%d%sB,%d%%", $1, $2, $3}')
|
# this could be done faster with 'stat --file-system --format'
|
||||||
printf "$(color M W)%s$(color -) " "$disk" | sed "s/\([0-9]\+\)/$(color -)$(color b M W)\1$(color -)$(color M W)/g"
|
# but then we'd have to do blocks -> human units ourselves
|
||||||
|
local out="" MP=$1 size="" pct="" unit=""
|
||||||
|
out=$({ df -h -P "$MP" 2>/dev/null || df -h "$MP"; } |
|
||||||
|
awk 'END { printf("%s %s", $2, $5); }')
|
||||||
|
set -- ${out}
|
||||||
|
size=${1}; pct=${2};
|
||||||
|
|
||||||
|
unit=${size#${size%?}} # get the unit (last char)
|
||||||
|
size=${size%?}; # take the unit off
|
||||||
|
pct=${pct%?}; # take off the '%'
|
||||||
|
|
||||||
|
_UNIT=${unit}; _SIZE=${size}; _PCT=${pct};
|
||||||
|
}
|
||||||
|
|
||||||
|
get_size_pct "${MP}"
|
||||||
|
|
||||||
|
color b M W; echo -n "$_SIZE"; color -; color M W; echo -n "${_UNIT}B,"; color -;
|
||||||
|
color b M W; echo -n "$_PCT"; color -; color M W; echo -n "%" ; color -;
|
||||||
|
|
|
@ -28,25 +28,35 @@ DIR="/sys/class/hwmon"
|
||||||
|
|
||||||
# Let's check a few different probes for fan speed
|
# Let's check a few different probes for fan speed
|
||||||
|
|
||||||
# This seems to cover most of them:
|
fan_speed_info() {
|
||||||
for i in $(find $DIR/*/*/ -type f -name "fan1_input"); do
|
local i="" speed=0
|
||||||
speed=$(cat "$i")
|
# This seems to cover most of them:
|
||||||
|
for i in /sys/class/hwmon/*/*/fan1_input; do
|
||||||
|
[ -f "$i" ] || continue
|
||||||
|
read speed < "$i"
|
||||||
if [ "$speed" -gt 0 ]; then
|
if [ "$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 --
|
||||||
exit 0
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# But others (e.g. Dell Inspirons) seem to be here:
|
# But others (e.g. Dell Inspirons) seem to be here:
|
||||||
if [ -r /proc/i8k ]; then
|
if [ -r /proc/i8k ]; then
|
||||||
for speed in $(awk '{ print $7, $8 }' /proc/i8k); do
|
local line=""
|
||||||
|
read line < /proc/i8k
|
||||||
|
set -- $line
|
||||||
|
for speed in $7 $8; do
|
||||||
if [ "$speed" -gt 0 ]; then
|
if [ "$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
|
||||||
[ "$speed" -gt 10000 ] && speed=$((${speed} / 30))
|
[ "$speed" -gt 10000 ] && speed=$((${speed} / 30))
|
||||||
color bold1; printf "%s" "$speed"; color -; color none; printf "rpm"; color --
|
color bold1; printf "%s" "$speed"; color -; color none; printf "rpm"; color --
|
||||||
exit 0
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
fan_speed_info "$@"
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,10 @@ if [ -n "$MONITORED_NETWORK" ]; then
|
||||||
interface="$MONITORED_NETWORK"
|
interface="$MONITORED_NETWORK"
|
||||||
else
|
else
|
||||||
case "$IPV6" in
|
case "$IPV6" in
|
||||||
1|true|yes) interface=$(grep -v "\Wlo$" /proc/net/ipv6_route | tail -n1 | awk '{print $10}') ;;
|
1|true|yes)
|
||||||
*) interface=$(tail -n1 /proc/net/route | awk '{print $1}') ;;
|
interface=$(awk '$10 != "lo" { iface=$10 ; }; END { print iface; }' \
|
||||||
|
/proc/net/ipv6_route);;
|
||||||
|
*) interface=$(awk 'END {print $1}' /proc/net/route);;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -26,19 +26,26 @@ if [ "$1" = "--detail" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
. "$DATA/status"
|
mem_available_info() {
|
||||||
[ "$mem_used" = "1" ] && comma="," || whitespace=" "
|
local mem_used comma whitespace unit mem name
|
||||||
|
. "$DATA/status"
|
||||||
|
[ "$mem_used" = "1" ] && comma="," || whitespace=" "
|
||||||
|
|
||||||
mem=`head -n1 /proc/meminfo | awk '{print $2}'`
|
read name mem unit < /proc/meminfo
|
||||||
if [ $mem -ge 1048576 ]; then
|
if [ $mem -ge 1048576 ]; then
|
||||||
mem=$(echo "$mem" | awk '{ printf "%.1f", $1 / 1048576 }')
|
fpdiv "$mem" 1048567 1
|
||||||
|
mem=${_RET}
|
||||||
unit="GB"
|
unit="GB"
|
||||||
elif [ $mem -ge 1024 ]; then
|
elif [ $mem -ge 1024 ]; then
|
||||||
mem=$(echo "$mem" | awk '{ printf "%.0f", $1 / 1024 }')
|
mem=$(echo "$mem" | awk '{ printf "%.0f", $1 / 1024 }')
|
||||||
|
fpdiv "$mem" 1024 1
|
||||||
|
mem=${_RET}
|
||||||
unit="MB"
|
unit="MB"
|
||||||
else
|
else
|
||||||
mem="$mem"
|
mem="$mem"
|
||||||
unit="KB"
|
unit="KB"
|
||||||
fi
|
fi
|
||||||
|
color b g W; printf "%s" "$mem"; color -; color g W; printf "%s%s" "$unit" "$comma"; color -; printf "%s" "$whitespace"
|
||||||
|
}
|
||||||
|
|
||||||
color b g W; printf "%s" "$mem"; color -; color g W; printf "%s%s" "$unit" "$comma"; color -; printf "%s" "$whitespace"
|
mem_available_info "$@"
|
||||||
|
|
|
@ -25,5 +25,41 @@ if [ "$1" = "--detail" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
f=$(free | awk '/buffers\/cache:/ {printf "%.0f", 100*$3/($3 + $4)}')
|
meminfo_used() {
|
||||||
|
# originally, this script did:
|
||||||
|
# f=$(free | awk '/buffers\/cache:/ {printf "%.0f", 100*$3/($3 + $4)}')
|
||||||
|
# this method is more dependent on /proc/meminfo, but uses the same formula
|
||||||
|
# for deriving the output of 'free' that is used in procps 'free.c'
|
||||||
|
|
||||||
|
# kb_main_free, kb_main_total, kb_main_buffers, kb_main_cached
|
||||||
|
local free="" total="" buffers="" cached=""
|
||||||
|
local kb_main_used=0 buffers_plus_cached=0 fo_buffers=0 fo_cached=0
|
||||||
|
while read tok val unit; do
|
||||||
|
case "$tok" in
|
||||||
|
MemTotal:) total=${val};;
|
||||||
|
MemFree:) free=${val};;
|
||||||
|
Buffers:) buffers=${val};;
|
||||||
|
Cached:) cached=${val};;
|
||||||
|
esac
|
||||||
|
[ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break;
|
||||||
|
done < /proc/meminfo
|
||||||
|
|
||||||
|
kb_main_used=$(($total-$free))
|
||||||
|
buffers_plus_cached=$(($buffers+$cached))
|
||||||
|
|
||||||
|
# "free output" buffers and cache (output from 'free')
|
||||||
|
fo_buffers=$(($kb_main_used - $buffers_plus_cached))
|
||||||
|
fo_cached=$(($kb_main_free + $buffers_plus_cached))
|
||||||
|
|
||||||
|
#fpdiv $((100*${fo_buffers})) "${total}" 0; _RET=${_RET%.}; return
|
||||||
|
_RET=$(((100*${fo_buffers}) / ${total}))
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -r /proc/meminfo ]; then
|
||||||
|
meminfo_used
|
||||||
|
f=${_RET}
|
||||||
|
else
|
||||||
|
f=$(free | awk '/buffers\/cache:/ {printf "%.0f", 100*$3/($3 + $4)}')
|
||||||
|
fi
|
||||||
|
|
||||||
color b g W; printf "%s" "$f"; color -; color g W; printf "%%"; color --
|
color b g W; printf "%s" "$f"; color -; color g W; printf "%%"; color --
|
||||||
|
|
|
@ -29,16 +29,18 @@ case $1 in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if grep -qs " blocks .*\[.*_.*\]$" /proc/mdstat; then
|
pct="%"
|
||||||
|
while read line; do
|
||||||
# Errors in your raid
|
# Errors in your raid
|
||||||
msg="RAID"
|
case "$line" in
|
||||||
fi
|
*\ blocks\ *\[*_*\]$)
|
||||||
|
[ -z "${msg}" ] && msg="RAID";;
|
||||||
if grep -qs \% /proc/mdstat; then
|
*%*)
|
||||||
p=$(grep -m1 \% /proc/mdstat | sed -e "s/\%.*/%/" -e "s/.* //")
|
p="${line%%${pct}*}${pct}"; p=${p##* };
|
||||||
[ -z "$msg" ] && msg="RAID"
|
[ -z "$msg" ] && msg="RAID"
|
||||||
msg="$msg,$p"
|
msg="$msg,$p";;
|
||||||
fi
|
esac
|
||||||
|
done < /proc/mdstat
|
||||||
|
|
||||||
if [ -n "$msg" ]; then
|
if [ -n "$msg" ]; then
|
||||||
color B w r; printf "%s" "$msg"; color --
|
color B w r; printf "%s" "$msg"; color --
|
||||||
|
|
|
@ -25,24 +25,30 @@ if [ "$1" = "--detail" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$DISTRO" ]; then
|
release_info() {
|
||||||
|
local DISTRO="${DISTRO}" issue ver r i
|
||||||
|
if [ -n "$DISTRO" ]; then
|
||||||
# user defined
|
# user defined
|
||||||
true
|
true
|
||||||
elif [ -r "/etc/issue" ]; then
|
elif [ -r "/etc/issue" ]; then
|
||||||
# lsb_release is *really* slow; try to use /etc/issue first
|
# lsb_release is *really* slow; try to use /etc/issue first
|
||||||
issue=$(grep -m1 "^[A-Za-z]" /etc/issue)
|
read issue < /etc/issue
|
||||||
case "$issue" in
|
case "$issue" in
|
||||||
Ubuntu*)
|
Ubuntu*)
|
||||||
DISTRO=$(head -n1 /etc/issue | awk '{print $1 " " $2}')
|
set -- $issue;
|
||||||
|
DISTRO="$1 $2";
|
||||||
;;
|
;;
|
||||||
Debian*)
|
Debian*)
|
||||||
DISTRO="Debian $(cat /etc/debian_version)"
|
read ver < /etc/debian_version
|
||||||
|
DISTRO="Debian $ver"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
DISTRO=$(echo "$issue" | sed "s/ [^0-9]* / /" | awk '{print $1 " " $2}')
|
# assume first 2 fields are what we want
|
||||||
|
set -- $issue;
|
||||||
|
DISTRO="$1 $2";
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
elif which lsb_release >/dev/null 2>&1; then
|
elif command -v lsb_release >/dev/null 2>&1; then
|
||||||
if [ "$1" = "--detail" ]; then
|
if [ "$1" = "--detail" ]; then
|
||||||
lsb_release -a 2>/dev/null
|
lsb_release -a 2>/dev/null
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -62,8 +68,11 @@ elif which lsb_release >/dev/null 2>&1; then
|
||||||
DISTRO="$i $r"
|
DISTRO="$i $r"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
DISTRO="Byobu"
|
DISTRO="Byobu"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
color bold2; printf "%s" "$DISTRO"; color --
|
color bold2; printf "%s" "$DISTRO"; color --
|
||||||
|
}
|
||||||
|
|
||||||
|
release_info "$@"
|
||||||
|
|
|
@ -25,19 +25,40 @@ if [ "$1" = "--detail" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
f=$(free | awk '/Swap:/ {printf "%.0f", 100*$3/($3 + $4)}' 2>/dev/null || echo 0)
|
swap_info() {
|
||||||
mem=$(free | awk '/Swap:/ {print $2}')
|
local stotal="" sfree="" name val unit mem f;
|
||||||
if [ $mem -ge 1048576 ]; then
|
while read name val unit; do
|
||||||
mem=$(echo "$mem" | awk '{ printf "%.1f", $1 / 1048576 }')
|
if [ "$name" = "SwapTotal:" ]; then
|
||||||
|
stotal="$val"
|
||||||
|
elif [ "$name" = "SwapFree:" ]; then
|
||||||
|
sfree="$val"
|
||||||
|
else
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
[ -n "$stotal" -a -n "$sfree" ] && break;
|
||||||
|
done < /proc/meminfo
|
||||||
|
|
||||||
|
[ "${stotal:-0}" = "0" ] && return 0
|
||||||
|
|
||||||
|
mem=${stotal}
|
||||||
|
f=$(((100*($stotal-$sfree))/$stotal))
|
||||||
|
[ "$f" = "0" ] && return 0
|
||||||
|
if [ $mem -ge 1048576 ]; then
|
||||||
|
fpdiv "${mem}" 1048576 1
|
||||||
|
mem=${_RET}
|
||||||
unit="GB"
|
unit="GB"
|
||||||
elif [ $mem -ge 1024 ]; then
|
elif [ $mem -ge 1024 ]; then
|
||||||
mem=$(echo "$mem" | awk '{ printf "%.0f", $1 / 1024 }')
|
fpdiv "${mem}" 1024 0
|
||||||
|
mem=${_RET%.}
|
||||||
unit="MB"
|
unit="MB"
|
||||||
else
|
else
|
||||||
mem="$mem"
|
mem="$mem"
|
||||||
unit="KB"
|
unit="KB"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ "$f" = "0" ] && exit 0
|
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 "%%"; color --
|
||||||
|
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 "%%"; color --
|
swap_info "$@"
|
||||||
|
|
|
@ -22,12 +22,12 @@ DATA="$HOME/.$PKG"
|
||||||
color 2>/dev/null || color() { true; }
|
color 2>/dev/null || color() { true; }
|
||||||
|
|
||||||
if [ "$1" = "--detail" -o "$1" = "--short" ]; then
|
if [ "$1" = "--detail" -o "$1" = "--short" ]; then
|
||||||
if which apt-get >/dev/null; then
|
if command -v apt-get >/dev/null; then
|
||||||
detail=`apt-get -s -o Debug::NoLocking=true upgrade`
|
detail=`apt-get -s -o Debug::NoLocking=true upgrade`
|
||||||
if [ "$1" = "--detail" ]; then
|
if [ "$1" = "--detail" ]; then
|
||||||
printf "$detail"
|
printf "$detail"
|
||||||
else
|
else
|
||||||
short=`printf "$detail" | grep -c ^Inst`
|
short=`printf "%s" "$detail" | grep -c ^Inst`
|
||||||
printf "$short"
|
printf "$short"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -61,18 +61,18 @@ update_cache() {
|
||||||
# and let the next cache check pick up the results.
|
# and let the next cache check pick up the results.
|
||||||
if [ -x /usr/lib/update-notifier/apt-check ]; then
|
if [ -x /usr/lib/update-notifier/apt-check ]; then
|
||||||
# If apt-check binary exists, use it
|
# If apt-check binary exists, use it
|
||||||
/usr/lib/update-notifier/apt-check 2>&1 | tail -n 1 | sed "s/;/ /" > $mycache &
|
/usr/lib/update-notifier/apt-check 2>&1 | awk '-F;' 'END { print $1, $2 }' > "$mycache" &
|
||||||
elif which apt-get >/dev/null; then
|
elif command -v apt-get >/dev/null; then
|
||||||
# If apt-get exists, use it
|
# If apt-get exists, use it
|
||||||
apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst > $mycache &
|
apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst > $mycache &
|
||||||
elif which zypper >/dev/null; then
|
elif command -v zypper >/dev/null; then
|
||||||
# If zypper exists, use it
|
# If zypper exists, use it
|
||||||
zypper --no-refresh lu --best-effort | grep -c 'v |' > $mycache &
|
zypper --no-refresh lu --best-effort | grep -c 'v |' > $mycache &
|
||||||
elif which yum >/dev/null; then
|
elif command -v yum >/dev/null; then
|
||||||
# If yum exists, use it
|
# If yum exists, use it
|
||||||
# TODO: We need a better way of counting updates available from a RH expert
|
# TODO: We need a better way of counting updates available from a RH expert
|
||||||
yum list updates -q | grep -vc "Updated Packages" > $mycache &
|
yum list updates -q | grep -vc "Updated Packages" > $mycache &
|
||||||
elif which pacman >/dev/null; then
|
elif command -v pacman >/dev/null; then
|
||||||
# If pacman (Archlinux) exists, use it
|
# If pacman (Archlinux) exists, use it
|
||||||
LC_ALL=C pacman -Sup | grep -vc "^\(::\| \)" > $mycache &
|
LC_ALL=C pacman -Sup | grep -vc "^\(::\| \)" > $mycache &
|
||||||
fi
|
fi
|
||||||
|
@ -84,11 +84,11 @@ update_needed() {
|
||||||
mycache=$1
|
mycache=$1
|
||||||
# The cache doesn't exist: create it
|
# The cache doesn't exist: create it
|
||||||
[ ! -e "$mycache" ] && return 0
|
[ ! -e "$mycache" ] && return 0
|
||||||
if which apt-get >/dev/null; then
|
if command -v apt-get >/dev/null; then
|
||||||
# Debian/ubuntu
|
# Debian/ubuntu
|
||||||
[ "/var/lib/apt" -nt "$mycache" ] || [ "/var/lib/apt/lists" -nt "$mycache" ]
|
[ "/var/lib/apt" -nt "$mycache" ] || [ "/var/lib/apt/lists" -nt "$mycache" ]
|
||||||
return $?
|
return $?
|
||||||
elif which pacman >/dev/null; then
|
elif command -v pacman >/dev/null; then
|
||||||
# Archlinux
|
# Archlinux
|
||||||
for db in /var/lib/pacman/sync/*.db; do
|
for db in /var/lib/pacman/sync/*.db; do
|
||||||
[ "$db" -nt "$mycache" ] && return 0
|
[ "$db" -nt "$mycache" ] && return 0
|
||||||
|
@ -102,7 +102,7 @@ update_needed() {
|
||||||
mycache="$DIR/$PKG.updates-available"
|
mycache="$DIR/$PKG.updates-available"
|
||||||
|
|
||||||
# If mycache is present, use it
|
# If mycache is present, use it
|
||||||
[ -r $mycache ] && print_updates `grep "^[0-9]" $mycache | sed "s/ .*$//"`
|
[ -r $mycache ] && print_updates `sed -n '/[^0-9]/s/ .*$//p' $mycache`
|
||||||
|
|
||||||
# If we really need to do so (mycache doesn't exist, or the package database has changed),
|
# If we really need to do so (mycache doesn't exist, or the package database has changed),
|
||||||
# background an update now
|
# background an update now
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue