From 71b2160207ab690fb78ee2f5737a35780b6f1c9a Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Tue, 16 Jun 2009 17:20:52 -0500 Subject: [PATCH] * bin/disk_available, bin/disk_used, bin/hostname, bin/ip_address, bin/mem_available, byobu-status: drop grepping of status config file, source it instead, should improve performance Signed-off-by: Dustin Kirkland --- bin/disk_available | 9 ++------- bin/disk_used | 8 +++----- bin/hostname | 4 ++-- bin/ip_address | 6 +++--- bin/mem_available | 11 +++-------- byobu-status | 1 + debian/changelog | 5 ++++- 7 files changed, 18 insertions(+), 26 deletions(-) diff --git a/bin/disk_available b/bin/disk_available index 789d976a..b39fdfb9 100755 --- a/bin/disk_available +++ b/bin/disk_available @@ -24,13 +24,8 @@ if [ "$1" = "--detail" ]; then exit 0 fi -comma= -whitespace= -if [ -r "$HOME/.$PKG/status" ]; then - grep -qs "^disk_used=1$" "$HOME/.$PKG/status" && comma="," || whitespace=" " -else - comma="," -fi +. "$HOME/.$PKG/status" 2>/dev/null || true +[ "$disk_used" = "1" ] && comma="," || whitespace=" " # Default to /, but let users override [ -r "$HOME/.$PKG/disk" ] && MP=`cat "$HOME/.$PKG/disk"` || MP="/" diff --git a/bin/disk_used b/bin/disk_used index d2882854..3a4d217a 100755 --- a/bin/disk_used +++ b/bin/disk_used @@ -24,13 +24,11 @@ if [ "$1" = "--detail" ]; then exit 0 fi -whitespace= -if [ -r "$HOME/.$PKG/status" ]; then - grep -qs "^date=1$" "$HOME/.$PKG/status" && whitespace=" " -fi +. "$HOME/.$PKG/status" 2>/dev/null || true +[ "$date" = "1" ] && trailer=" " # Default to /, but let users override [ -r "$HOME/.$PKG/disk" ] && MP=`cat "$HOME/.$PKG/disk"` || MP="/" used=`df -h -P "$MP" | tail -n 1 | sed "s/%.*$/%/" | sed "s/^.* //"` -printf "\005{= MW}%s\005{-}%s" "$used" "$whitespace" +printf "\005{= MW}%s\005{-}%s" "$used" "$trailer" diff --git a/bin/hostname b/bin/hostname index 93dc04a0..844bbcc6 100755 --- a/bin/hostname +++ b/bin/hostname @@ -24,7 +24,7 @@ if [ "$1" = "--detail" ]; then exit 0 fi -at= -grep -qs "^whoami=1$" "$HOME/.$PKG/status" && at="@" +. "$HOME/.$PKG/status" 2>/dev/null || true +[ "$whoami" = "1" ] && at="@" printf "\005{+b }%s%s\005{-}" "$at" $(hostname -s 2>/dev/null || hostname) diff --git a/bin/ip_address b/bin/ip_address index 71d64392..0661a7f6 100755 --- a/bin/ip_address +++ b/bin/ip_address @@ -24,9 +24,9 @@ if [ "$1" = "--detail" ]; then exit 0 fi -space= -grep -qs "^hostname=1$" "$HOME/.$PKG/status" && space=" " -grep -qs "^whoami=1$" "$HOME/.$PKG/status" && space=" " +. "$HOME/.$PKG/status" 2>/dev/null || true +[ "$hostname" = "1" ] && space=" " +[ "$whoami" = "1" ] && space=" " interface=`/sbin/route -n | tail -n 1 | sed "s/^.* //"` ipaddr=`/sbin/ifconfig "$interface" | grep "inet addr:" | sed "s/^.*inet addr://" | sed "s/ .*$//"` diff --git a/bin/mem_available b/bin/mem_available index e3630500..bc6ce469 100755 --- a/bin/mem_available +++ b/bin/mem_available @@ -24,13 +24,8 @@ if [ "$1" = "--detail" ]; then exit 0 fi -comma= -whitespace= -if [ -r "$HOME/.$PKG/status" ]; then - grep -qs "^mem_used=1$" "$HOME/.$PKG/status" && comma="," || whitespace=" " -else - comma="," -fi +. "$HOME/.$PKG/status" 2>/dev/null || true +[ "$mem_used" = "1" ] && comma="," || whitespace=" " mem=`free | grep -m 1 "^Mem:" | awk '{print $2}'` if [ $mem -ge 1048576 ]; then @@ -43,4 +38,4 @@ else mem="$mem" unit="KB" fi -printf "\005{= gW}%s$unit$comma\005{-}%s" "$mem" "$whitespace" +printf "\005{= gW}%s$unit%s\005{-}%s" "$mem" "$comma" "$whitespace" diff --git a/byobu-status b/byobu-status index dae7889d..a92871a4 100755 --- a/byobu-status +++ b/byobu-status @@ -66,6 +66,7 @@ fi P="$1" eval x=\$$P +export $P case "$P" in # default = on, user must override to turn off diff --git a/debian/changelog b/debian/changelog index c585af4c..7573770e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,8 +18,11 @@ byobu (2.12) unreleased; urgency=low byobu-status, byobu.1, rpm/byobu.spec: merge network_down and network_up to a single status script; too much duplication of code, causes performance problems + * bin/disk_available, bin/disk_used, bin/hostname, bin/ip_address, + bin/mem_available, byobu-status: drop grepping of status config file, + source it instead, should improve performance - -- Dustin Kirkland Tue, 16 Jun 2009 16:40:12 -0500 + -- Dustin Kirkland Tue, 16 Jun 2009 17:20:46 -0500 byobu (2.11-0ubuntu1) karmic; urgency=low