mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-22 22:34:23 -07:00
speedups from scott
This commit is contained in:
commit
e0201c88d8
23 changed files with 413 additions and 223 deletions
|
@ -25,7 +25,7 @@ export BYOBU_PREFIX
|
|||
RUN="$SOCKETDIR/S-$USER"
|
||||
DATA="$HOME/.$PKG"
|
||||
|
||||
. "${BYOBU_PREFIX}/usr/lib/${PKG}/.shutil"
|
||||
. "${BYOBU_PREFIX}/lib/${PKG}/.shutil"
|
||||
if [ ! -x "$BYOBU_PREFIX/bin/$PKG" ]; then
|
||||
error "Cannot find $BYOBU_PREFIX/bin/$PKG"
|
||||
error "If you have installed it elsewhere, export BYOBU_PREFIX in your shell"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
PKG="byobu"
|
||||
|
||||
. "${BYOBU_PREFIX}/usr/lib/${PKG}/.shutil"
|
||||
. "${BYOBU_PREFIX}/lib/${PKG}/.shutil"
|
||||
|
||||
case "$-" in
|
||||
*i*)
|
||||
|
|
|
@ -21,18 +21,11 @@ PKG="byobu"
|
|||
DATA="$HOME/.$PKG"
|
||||
[ -z "$BYOBU_PREFIX" ] && export BYOBU_PREFIX="/usr" || export BYOBU_PREFIX
|
||||
|
||||
find_script () {
|
||||
# Allow for local status scripts
|
||||
if [ -x "$DATA/bin/$1" ]; then
|
||||
_RET="$DATA/bin/$1"
|
||||
elif [ -x "$BYOBU_PREFIX/lib/$PKG/$1" ]; then
|
||||
_RET="$BYOBU_PREFIX/lib/$PKG/$1"
|
||||
elif [ -x "$BYOBU_PREFIX/libexec/$PKG/$1" ]; then
|
||||
_RET="$BYOBU_PREFIX/libexec/$PKG/$1"
|
||||
else
|
||||
_RET="/dev/null"
|
||||
if ! . "${BYOBU_PREFIX}/lib/${PKG}/.shutil"; then
|
||||
echo "failed to source ${BYOBU_PREFIX}/lib/${PKG}/.shutil" 2>&1
|
||||
echo "If you have installed elsewhere, export BYOBU_PREFIX in your shell" 2>&1
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Define colors
|
||||
ESC="\005"
|
||||
|
|
|
@ -23,3 +23,57 @@ error() {
|
|||
fail() {
|
||||
[ $# -eq 0 ] || error "$@"; exit 1;
|
||||
}
|
||||
|
||||
find_script() {
|
||||
# Allow for local status scripts
|
||||
if [ -x "$DATA/bin/$1" ]; then
|
||||
_RET="$DATA/bin/$1"
|
||||
elif [ -x "$BYOBU_PREFIX/lib/$PKG/$1" ]; then
|
||||
_RET="$BYOBU_PREFIX/lib/$PKG/$1"
|
||||
elif [ -x "$BYOBU_PREFIX/libexec/$PKG/$1" ]; then
|
||||
_RET="$BYOBU_PREFIX/libexec/$PKG/$1"
|
||||
else
|
||||
_RET="/dev/null"
|
||||
fi
|
||||
}
|
||||
|
||||
# divide 2 integers and return a floating point number
|
||||
# third argument indicates how many digits after the decimal
|
||||
fpdiv() {
|
||||
local a=$1 b=$2 pres=${3:-3}
|
||||
local i=0 mp="10" whole="" part=""
|
||||
while i=$(($i+1)) && [ $i -le $pres ]; do
|
||||
mp="${mp}0"
|
||||
done
|
||||
whole=$(($a/$b))
|
||||
part=$((((($a%$b)*${mp})/$b)))
|
||||
if [ $part -eq 0 ]; then
|
||||
part=${part#1};
|
||||
elif [ $((${part}%(${mp}/10))) -ge 5 ]; then
|
||||
part=$(($part+5))
|
||||
fi
|
||||
_RET="${whole}.${part%?}"
|
||||
}
|
||||
|
||||
# rtrim(string,chars)
|
||||
rtrim() {
|
||||
local tab=' ' cr="
|
||||
"
|
||||
local cur="${1}" set="[${2:- ${tab}${cr}}]" n=""
|
||||
while n=${cur%${set}} && [ "$n" != "$cur" ]; do cur=${n}; done
|
||||
_RET=${cur}
|
||||
}
|
||||
|
||||
readfile() {
|
||||
local c="" r="" cr="
|
||||
"
|
||||
OIFS="$IFS"; IFS="";
|
||||
while read c; do
|
||||
r="$r${cr}$c"
|
||||
done
|
||||
IFS=$OIFS
|
||||
_RET=${r}
|
||||
return 0
|
||||
}
|
||||
|
||||
# vi: syntax=sh ts=4 noexpandtab
|
||||
|
|
|
@ -21,14 +21,6 @@
|
|||
PKG="byobu"
|
||||
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
|
||||
for bat in /proc/acpi/battery/*; do
|
||||
cat "$bat/info"
|
||||
|
@ -37,18 +29,35 @@ if [ "$1" = "--detail" ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
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
|
||||
infofile=$(cat "$bat/info")
|
||||
present=$(search "$infofile" "present: *\(.*\)")
|
||||
[ "${present}" = "no" ] && continue
|
||||
[ "$2" = "no" ] && continue 2
|
||||
present="$2";;
|
||||
last\ full\ capacity:*) full="$4";;
|
||||
esac
|
||||
[ -n "$present" -a -n "$full" ] && break
|
||||
done < "${bat}/info"
|
||||
|
||||
# obtain full and remaining battery values
|
||||
statefile=$(cat "$bat/state")
|
||||
full=$(search "$infofile" "last full capacity: *\(.*\) m[AW]h")
|
||||
rem=$(search "$statefile" "remaining capacity: *\(.*\) m[AW]h")
|
||||
while read line; do
|
||||
set -- ${line}
|
||||
case "$line" in
|
||||
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
|
||||
color="R k"
|
||||
bcolor="b R k"
|
||||
|
@ -61,22 +70,15 @@ for bat in $BATTERY /proc/acpi/battery/*; do
|
|||
fi
|
||||
percent="$percent%"
|
||||
|
||||
state=$(search "$statefile" "charging state: *\(.*\)")
|
||||
case $state in
|
||||
charging)
|
||||
sign="+"
|
||||
;;
|
||||
discharging)
|
||||
sign="-"
|
||||
;;
|
||||
charged)
|
||||
sign="="
|
||||
percent=
|
||||
;;
|
||||
*)
|
||||
sign="$state"
|
||||
;;
|
||||
charging) sign="+" ;;
|
||||
discharging) sign="-" ;;
|
||||
charged) sign="="; percent="" ;;
|
||||
*) sign="$state" ;;
|
||||
esac
|
||||
color $bcolor; printf "%s" "$percent"; color -; color $color; printf "|%s|" "$sign"; color --
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
battery_info "$@"
|
||||
|
|
|
@ -26,7 +26,9 @@ if [ "$1" = "--detail" ]; then
|
|||
fi
|
||||
|
||||
if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ]; then
|
||||
freq=$(awk '{ printf "%.1f", $1 / 1000000 }' /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)
|
||||
read hz < /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
|
||||
fpdiv $hz "1000000" 1 # 1Ghz
|
||||
freq="$_RET"
|
||||
else
|
||||
if egrep -q -s -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo; then
|
||||
freq=$(egrep -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo | awk -F"[:.]" '{ printf "%.1f", $2 / 1000 }')
|
||||
|
|
|
@ -36,7 +36,7 @@ fi
|
|||
for i in $MONITORED_TEMP /sys/class/hwmon/hwmon*/temp*_input /proc/acpi/ibm/thermal $DIR/*/temperature; do
|
||||
case "$i" in
|
||||
*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")
|
||||
|
@ -45,7 +45,7 @@ for i in $MONITORED_TEMP /sys/class/hwmon/hwmon*/temp*_input /proc/acpi/ibm/ther
|
|||
if [ -n "$t" ]; then
|
||||
unit="$ICON_C"
|
||||
if [ "$TEMP" = "F" ]; then
|
||||
t=$(echo "$t" | awk '{printf "%.0f", $1 *9/5 + 32}')
|
||||
t=$(($t*9/5 + 32))
|
||||
unit="$ICON_F"
|
||||
fi
|
||||
color b k Y; printf "%s" "$t"; color -; color k Y; printf "%s%s" "$ICON" "$unit"; color --
|
||||
|
|
|
@ -30,15 +30,18 @@ CACHE="$DIR/$PKG.custom"
|
|||
# Loop over custom scripts
|
||||
for i in "$DATA/bin/"[0-9]*_*; do
|
||||
[ -x "$i" ] || continue
|
||||
script=$(basename "$i")
|
||||
freq=$(echo "$script" | awk -F_ '{print $1}')
|
||||
lastrun=$(stat -c %Y "$CACHE.$script") 2>/dev/null || lastrun=0
|
||||
expiration=$(expr $lastrun + $freq)
|
||||
script=${script##*/}
|
||||
freq=${script%%_*}
|
||||
freq=${freq#0}
|
||||
[ -r "$CACHE.$script.last" ] && read lastrun "$CACHE.$script.last" ||
|
||||
lastrun=0
|
||||
expiration=$(($lastrun+$freq))
|
||||
if [ $NOW -ge $expiration ]; then
|
||||
# Update the cache
|
||||
$i $@ > "$CACHE.$script" 2>/dev/null
|
||||
"$i" "$@" > "$CACHE.$script" 2>/dev/null
|
||||
echo "${NOW}" > "$CACHE.$script.last"
|
||||
fi
|
||||
output=$(cat "$CACHE.$script")
|
||||
readfile < "$CACHE.$script"
|
||||
output="${_RET}"
|
||||
case "$output" in
|
||||
*"$ESC{"*)
|
||||
# User has formatted the colors
|
||||
|
|
|
@ -25,8 +25,10 @@ case "$1" in
|
|||
date +%Y-%m-%d
|
||||
;;
|
||||
*)
|
||||
msg="$(echo SGFwcHkgQmlydGhkYXkgU2NyZWVuIC0tIGh0dHA6Ly9iaXQubHkvc2NyZWVuLWJkYXkK | base64 -di)"
|
||||
[ "$(date +%d)" = "20" ] && [ "$(date +%m)" = "03" ] && screen -X -S "byobu" at "*" echo "[$msg]"
|
||||
bd=$(date "+%m%d")
|
||||
[ "$bd" = "0320" ] &&
|
||||
msg="$(echo SGFwcHkgQmlydGhkYXkgU2NyZWVuIC0tIGh0dHA6Ly9iaXQubHkvc2NyZWVuLWJkYXkK | base64 -di)" &&
|
||||
screen -X -S "byobu" at "*" echo "[$msg]"
|
||||
printf "\005Y-\005m-\005d "
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -28,9 +28,26 @@ fi
|
|||
# Default to /, but let users override
|
||||
[ -z "$MONITORED_DISK" ] && MP="/" || MP="$MONITORED_DISK"
|
||||
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
|
||||
|
||||
disk=$(df -h -P "$MP" 2>/dev/null || df -h "$MP")
|
||||
disk=$(echo "$disk" | tail -n 1 | awk '{print $2 " " $5}' | sed "s/\([^0-9\. ]\)/ \1/g" | awk '{printf "%d%sB,%d%%", $1, $2, $3}')
|
||||
printf "$(color M W)%s$(color -) " "$disk" | sed "s/\([0-9]\+\)/$(color -)$(color b M W)\1$(color -)$(color M W)/g"
|
||||
get_size_pct() {
|
||||
# this could be done faster with 'stat --file-system --format'
|
||||
# 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 -;
|
||||
|
|
|
@ -20,20 +20,26 @@
|
|||
PKG="byobu"
|
||||
DATA="$HOME/.$PKG"
|
||||
color 2>/dev/null || color() { true; }
|
||||
getdisk() {
|
||||
local t=""
|
||||
if [ -L "${1}" ]; then
|
||||
command -v greadlink >/dev/null && READLINK=greadlink || READLINK=readlink
|
||||
t=$($READLINK -f "$1")
|
||||
else
|
||||
t="$1"
|
||||
fi
|
||||
t="${t##*/}";
|
||||
rtrim "$t" "0-9"
|
||||
}
|
||||
|
||||
[ "$UTF8" = "1" ] && ICON_RD="◀" || ICON_RD="<"
|
||||
[ "$UTF8" = "1" ] && ICON_WR="▶" || ICON_WR=">"
|
||||
|
||||
# Default to disk providing /, but let users override with MONITORED_DISK
|
||||
[ -z "$MONITORED_DISK" ] && MP="/" || MP="$MONITORED_DISK"
|
||||
case $MP in
|
||||
/dev/*) disk="$MP" ;;
|
||||
*) disk=$(grep -m 1 " $MP " /etc/mtab | sed -e "s: .*$::") ;;
|
||||
esac
|
||||
which greadlink 2>/dev/null && READLINK="greadlink" || READLINK="readlink"
|
||||
disk=$($READLINK -f "$disk" | sed -e "s: .*$::" -e "s:^.*/::" -e "s:\([hsv]d[a-z]\)[0-9]*$:\1:")
|
||||
|
||||
if [ "$1" = "--detail" ]; then
|
||||
if which iostat >/dev/null; then
|
||||
if command -v >/dev/null; then
|
||||
iostat -d -m -h
|
||||
else
|
||||
echo "Please install iostat if you want detailed information on your disk throughput"
|
||||
|
@ -41,6 +47,13 @@ if [ "$1" = "--detail" ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
case "$MP" in
|
||||
/dev/*) part="${MP}";;
|
||||
*) part=$(awk '$2 == mp { print $1 ; exit(0); }' "mp=$MP" /etc/mtab);;
|
||||
esac
|
||||
getdisk "$part"
|
||||
disk=${_RET}
|
||||
|
||||
[ -d "/var/run/screen/S-$USER" ] && DIR="/var/run/screen/S-$USER" || DIR="$DATA"
|
||||
t2=`date +%s`
|
||||
for i in "read" "write"; do
|
||||
|
@ -50,20 +63,21 @@ for i in "read" "write"; do
|
|||
if [ $t2 -le $t1 ]; then
|
||||
rate=0
|
||||
else
|
||||
x1=`cat "$cache"` 2>/dev/null || tx1=0
|
||||
[ -r "$cache" ] && read x1 < "$cache" || x1=0
|
||||
read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 other < "/sys/block/$disk/stat"
|
||||
if [ "$i" = "read" ]; then
|
||||
symbol="$ICON_RD"
|
||||
x2=`awk '{print $3}' /sys/block/$disk/stat`
|
||||
x2="$a3"
|
||||
else
|
||||
symbol="$ICON_WR"
|
||||
x2=`awk '{print $7}' /sys/block/$disk/stat`
|
||||
x2="$a7"
|
||||
fi
|
||||
echo "$x2" > "$cache"
|
||||
rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) * 512 / 1024 }'`
|
||||
rate=$((($x2-$x1) / ($t2 - $t1) * 512 / 1024))
|
||||
if [ "$rate" -lt 0 ]; then
|
||||
rate=0
|
||||
elif [ "$rate" -gt 1024 ]; then
|
||||
rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'`
|
||||
fpdiv "$rate" 1024 1
|
||||
unit="MB/s"
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -28,25 +28,35 @@ DIR="/sys/class/hwmon"
|
|||
|
||||
# Let's check a few different probes for fan speed
|
||||
|
||||
fan_speed_info() {
|
||||
local i="" speed=0
|
||||
# This seems to cover most of them:
|
||||
for i in $(find $DIR/*/*/ -type f -name "fan1_input"); do
|
||||
speed=$(cat "$i")
|
||||
for i in /sys/class/hwmon/*/*/fan1_input; do
|
||||
[ -f "$i" ] || continue
|
||||
read speed < "$i"
|
||||
if [ "$speed" -gt 0 ]; then
|
||||
color bold1; printf "%s" "$speed"; color -; color none; printf "rpm"; color --
|
||||
exit 0
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
# But others (e.g. Dell Inspirons) seem to be here:
|
||||
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
|
||||
# I8K_FAN_MULT defaults to 30 (buggy BIOS workaround?),
|
||||
# use `modprobe i8k fan_mult=1` to disable if unneeded,
|
||||
# resulting in nonsensical speeds
|
||||
[ "$speed" -gt 10000 ] && speed=$((${speed} / 30))
|
||||
color bold1; printf "%s" "$speed"; color -; color none; printf "rpm"; color --
|
||||
exit 0
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
fan_speed_info "$@"
|
||||
|
||||
|
|
|
@ -35,8 +35,10 @@ if [ -n "$MONITORED_NETWORK" ]; then
|
|||
interface="$MONITORED_NETWORK"
|
||||
else
|
||||
case "$IPV6" in
|
||||
1|true|yes) interface=$(grep -v "\Wlo$" /proc/net/ipv6_route | tail -n1 | awk '{print $10}') ;;
|
||||
*) interface=$(tail -n1 /proc/net/route | awk '{print $1}') ;;
|
||||
1|true|yes)
|
||||
interface=$(awk '$10 != "lo" { iface=$10 ; }; END { print iface; }' \
|
||||
/proc/net/ipv6_route);;
|
||||
*) interface=$(awk 'END {print $1}' /proc/net/route);;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
|
|
@ -24,5 +24,5 @@ if [ "$1" = "--detail" ]; then
|
|||
cat /proc/loadavg
|
||||
exit 0
|
||||
fi
|
||||
|
||||
color Y k; printf "%s" "$(awk '{print $1}' /proc/loadavg)"; color --
|
||||
read one five fifteen other < /proc/loadavg
|
||||
color Y k; printf "$one"; color --
|
||||
|
|
|
@ -26,19 +26,26 @@ if [ "$1" = "--detail" ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
mem_available_info() {
|
||||
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
|
||||
mem=$(echo "$mem" | awk '{ printf "%.1f", $1 / 1048576 }')
|
||||
fpdiv "$mem" 1048567 1
|
||||
mem=${_RET}
|
||||
unit="GB"
|
||||
elif [ $mem -ge 1024 ]; then
|
||||
mem=$(echo "$mem" | awk '{ printf "%.0f", $1 / 1024 }')
|
||||
fpdiv "$mem" 1024 1
|
||||
mem=${_RET}
|
||||
unit="MB"
|
||||
else
|
||||
mem="$mem"
|
||||
unit="KB"
|
||||
fi
|
||||
|
||||
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
|
||||
fi
|
||||
|
||||
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 --
|
||||
|
|
|
@ -27,7 +27,8 @@ color 2>/dev/null || color() { true; }
|
|||
if [ -n "$MONITORED_NETWORK" ]; then
|
||||
interface="$MONITORED_NETWORK"
|
||||
else
|
||||
interface=`tail -n1 /proc/net/route | awk '{print $1}'`
|
||||
# get the last interface listed in /proc/net/route
|
||||
while read cn other; do interface=$cn; done < /proc/net/route
|
||||
fi
|
||||
|
||||
if [ "$1" = "--detail" ]; then
|
||||
|
@ -48,24 +49,27 @@ for i in up down; do
|
|||
if [ $t2 -le $t1 ]; then
|
||||
rate=0
|
||||
else
|
||||
x1=`cat "$cache"` 2>/dev/null || tx1=0
|
||||
if [ "$i" = "up" ]; then
|
||||
x2=`grep -m1 "\b$interface:" /proc/net/dev | sed "s/^.*://" | awk '{print $9}'`
|
||||
else
|
||||
x2=`grep -m1 "\b$interface:" /proc/net/dev | sed "s/^.*://" | awk '{print $1}'`
|
||||
[ -r "$cache" ] && read x1 < "$cache" || tx1=0
|
||||
while read iface rbytes rpackets rerrs rdrop rfifo rframe rcompressed rmulticast tbytes tpackets terrs tdrop tfifo tcolls tcarrier tcompressed; do
|
||||
if [ "$iface" = "${interface}:" ]; then
|
||||
[ "$i" = "up" ] && x2=${tbytes} || x2=${rbytes}
|
||||
break;
|
||||
fi
|
||||
done < /proc/net/dev
|
||||
echo "$x2" > "$cache"
|
||||
rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) / 1024 }'`
|
||||
rate=$((($x2 - $x1) / ($t2 - $t1) / 1024))
|
||||
if [ "$rate" -lt 0 ]; then
|
||||
rate=0
|
||||
fi
|
||||
case "$NETWORK_UNITS" in
|
||||
bytes)
|
||||
if [ "$rate" -gt 1048576 ]; then
|
||||
rate=`echo "$rate" | awk '{printf "%.1f", $1/1048576}'`
|
||||
fpdiv "$rate" 1048576 1
|
||||
rate=${_RET}
|
||||
unit="GB/s"
|
||||
elif [ "$rate" -gt 1024 ]; then
|
||||
rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'`
|
||||
fpdiv "$rate" 1024 1
|
||||
rate=${_RET}
|
||||
unit="MB/s"
|
||||
else
|
||||
unit="kB/s"
|
||||
|
@ -73,13 +77,15 @@ for i in up down; do
|
|||
;;
|
||||
*)
|
||||
# Default to bps
|
||||
rate=`echo "$rate" | awk '{printf "%.0f", $1*8}'`
|
||||
rate=$(($rate*8))
|
||||
# Why 1000 and not 1024? http://en.wikipedia.org/wiki/Data_rate_units
|
||||
if [ "$rate" -gt 1000000 ]; then
|
||||
rate=`echo "$rate" | awk '{printf "%.1f", $1/1000000}'`
|
||||
fpdiv "$rate" 1000000 1
|
||||
rate=${_RET}
|
||||
unit="Gbps"
|
||||
elif [ "$rate" -gt 1000 ]; then
|
||||
rate=`echo "$rate" | awk '{printf "%.1f", $1/1000}'`
|
||||
fpdiv "$rate" 1000 1
|
||||
rate=${_RET}
|
||||
unit="Mbps"
|
||||
fi
|
||||
;;
|
||||
|
|
|
@ -29,16 +29,18 @@ case $1 in
|
|||
;;
|
||||
esac
|
||||
|
||||
if grep -qs " blocks .*\[.*_.*\]$" /proc/mdstat; then
|
||||
pct="%"
|
||||
while read line; do
|
||||
# Errors in your raid
|
||||
msg="RAID"
|
||||
fi
|
||||
|
||||
if grep -qs \% /proc/mdstat; then
|
||||
p=$(grep -m1 \% /proc/mdstat | sed -e "s/\%.*/%/" -e "s/.* //")
|
||||
case "$line" in
|
||||
*\ blocks\ *\[*_*\]$)
|
||||
[ -z "${msg}" ] && msg="RAID";;
|
||||
*%*)
|
||||
p="${line%%${pct}*}${pct}"; p=${p##* };
|
||||
[ -z "$msg" ] && msg="RAID"
|
||||
msg="$msg,$p"
|
||||
fi
|
||||
msg="$msg,$p";;
|
||||
esac
|
||||
done < /proc/mdstat
|
||||
|
||||
if [ -n "$msg" ]; then
|
||||
color B w r; printf "%s" "$msg"; color --
|
||||
|
|
|
@ -25,24 +25,30 @@ if [ "$1" = "--detail" ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
release_info() {
|
||||
local DISTRO="${DISTRO}" issue ver r i
|
||||
if [ -n "$DISTRO" ]; then
|
||||
# user defined
|
||||
true
|
||||
elif [ -r "/etc/issue" ]; then
|
||||
# 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
|
||||
Ubuntu*)
|
||||
DISTRO=$(head -n1 /etc/issue | awk '{print $1 " " $2}')
|
||||
set -- $issue;
|
||||
DISTRO="$1 $2";
|
||||
;;
|
||||
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
|
||||
elif which lsb_release >/dev/null 2>&1; then
|
||||
elif command -v lsb_release >/dev/null 2>&1; then
|
||||
if [ "$1" = "--detail" ]; then
|
||||
lsb_release -a 2>/dev/null
|
||||
exit 0
|
||||
|
@ -67,3 +73,6 @@ else
|
|||
fi
|
||||
|
||||
color bold2; printf "%s" "$DISTRO"; color --
|
||||
}
|
||||
|
||||
release_info "$@"
|
||||
|
|
|
@ -25,19 +25,40 @@ if [ "$1" = "--detail" ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
f=$(free | awk '/Swap:/ {printf "%.0f", 100*$3/($3 + $4)}' 2>/dev/null || echo 0)
|
||||
mem=$(free | awk '/Swap:/ {print $2}')
|
||||
swap_info() {
|
||||
local stotal="" sfree="" name val unit mem f;
|
||||
while read name val unit; do
|
||||
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
|
||||
mem=$(echo "$mem" | awk '{ printf "%.1f", $1 / 1048576 }')
|
||||
fpdiv "${mem}" 1048576 1
|
||||
mem=${_RET}
|
||||
unit="GB"
|
||||
elif [ $mem -ge 1024 ]; then
|
||||
mem=$(echo "$mem" | awk '{ printf "%.0f", $1 / 1024 }')
|
||||
fpdiv "${mem}" 1024 0
|
||||
mem=${_RET%.}
|
||||
unit="MB"
|
||||
else
|
||||
mem="$mem"
|
||||
unit="KB"
|
||||
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; }
|
||||
|
||||
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`
|
||||
if [ "$1" = "--detail" ]; then
|
||||
printf "$detail"
|
||||
else
|
||||
short=`printf "$detail" | grep -c ^Inst`
|
||||
short=`printf "%s" "$detail" | grep -c ^Inst`
|
||||
printf "$short"
|
||||
fi
|
||||
fi
|
||||
|
@ -61,18 +61,18 @@ update_cache() {
|
|||
# and let the next cache check pick up the results.
|
||||
if [ -x /usr/lib/update-notifier/apt-check ]; then
|
||||
# If apt-check binary exists, use it
|
||||
/usr/lib/update-notifier/apt-check 2>&1 | tail -n 1 | sed "s/;/ /" > $mycache &
|
||||
elif which apt-get >/dev/null; then
|
||||
/usr/lib/update-notifier/apt-check 2>&1 | awk '-F;' 'END { print $1, $2 }' > "$mycache" &
|
||||
elif command -v apt-get >/dev/null; then
|
||||
# If apt-get exists, use it
|
||||
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
|
||||
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
|
||||
# TODO: We need a better way of counting updates available from a RH expert
|
||||
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
|
||||
LC_ALL=C pacman -Sup | grep -vc "^\(::\| \)" > $mycache &
|
||||
fi
|
||||
|
@ -84,11 +84,11 @@ update_needed() {
|
|||
mycache=$1
|
||||
# The cache doesn't exist: create it
|
||||
[ ! -e "$mycache" ] && return 0
|
||||
if which apt-get >/dev/null; then
|
||||
if command -v apt-get >/dev/null; then
|
||||
# Debian/ubuntu
|
||||
[ "/var/lib/apt" -nt "$mycache" ] || [ "/var/lib/apt/lists" -nt "$mycache" ]
|
||||
return $?
|
||||
elif which pacman >/dev/null; then
|
||||
elif command -v pacman >/dev/null; then
|
||||
# Archlinux
|
||||
for db in /var/lib/pacman/sync/*.db; do
|
||||
[ "$db" -nt "$mycache" ] && return 0
|
||||
|
@ -102,7 +102,7 @@ update_needed() {
|
|||
mycache="$DIR/$PKG.updates-available"
|
||||
|
||||
# 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),
|
||||
# background an update now
|
||||
|
|
|
@ -28,15 +28,17 @@ if [ "$1" = "--detail" ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
u=$(sed "s/\..*$//" /proc/uptime)
|
||||
read u idle < /proc/uptime
|
||||
u=${u%.*}
|
||||
color w b
|
||||
if [ "$u" -gt 86400 ]; then
|
||||
echo "$u" | awk '{printf "%dd%dh", $1 / 86400, ($1 % 86400)/3600 }'
|
||||
str="$(($u / 86400))d%$((($u % 86400) / 3600))h"
|
||||
elif [ "$u" -gt 3600 ]; then
|
||||
echo "$u" | awk '{printf "%dh%dm", $1 / 3600, ($1 % 3600 )/60}'
|
||||
str="$(($u / 3600))h$((($u % 3600) / 60))m"
|
||||
elif [ "$u" -gt 60 ]; then
|
||||
echo "$u" | awk '{printf "%dm", $1 / 60 }'
|
||||
str="$(($u / 60))m"
|
||||
else
|
||||
printf "%ds" "$u"
|
||||
str="${u}s"
|
||||
fi
|
||||
printf "%s" "${str}"
|
||||
color --
|
||||
|
|
|
@ -26,14 +26,22 @@ if [ "$1" = "--detail" ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
iwconfig=`/sbin/iwconfig $MONITORED_NETWORK 2>/dev/null`
|
||||
bitrate=`echo "$iwconfig" | grep "Bit Rate." | sed -e "s/^.*Bit Rate.//" -e "s/ .*$//g"`
|
||||
# iwconfig is expected to output lines like:
|
||||
# Bit Rate=54 Mb/s Tx-Power=15 dBm
|
||||
# Link Quality=60/70 Signal level=-50 dBm
|
||||
# the awk below tokenizes the output and prints shell evalable results
|
||||
out=`iwconfig $MONITORED_NETWORK 2>/dev/null |
|
||||
awk '$0 ~ /[ ]*Link Quality./ {
|
||||
sub(/.*=/,"",$2); split($2,a,"/");
|
||||
printf "quality=%.0f\n", 100*a[1]/a[2] };
|
||||
$0 ~ /[ ]*Bit Rate/ { sub(/.*=/,"",$2); printf("bitrate=%s\n", $2); }
|
||||
'`
|
||||
eval "$out"
|
||||
|
||||
[ -z "$bitrate" ] && bitrate="0"
|
||||
quality=`echo "$iwconfig" | grep "Link Quality." | sed -e "s/^.*Link Quality.//" -e "s/ .*$//g"`
|
||||
|
||||
if [ -z "$quality" ] || [ "$quality" = "0" ]; then
|
||||
quality="0"
|
||||
else
|
||||
quality=`echo "$quality" | awk -F/ '{printf "%.0f", 100*$1/$2}'`
|
||||
fi
|
||||
[ "$quality" = "0" ] && exit 0
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue