From 3adea2d373686768e6fc467114f717f97e121d5d Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Mon, 27 Apr 2009 21:14:43 -0500 Subject: [PATCH] Detailed status * bin/*: add special actions if --detail is specified; basically, print all relevant information on stdout without formatting * screen-profiles-status: add support for --detail, loop through all status scripts with --detail specified * screen-profiles-status-detail: wrapper using sensible-pager * screen-profiles-status-detail.1: documentation added Signed-off-by: Dustin Kirkland --- bin/arch | 5 ++++ bin/battery | 8 +++++++ bin/cpu-count | 4 ++++ bin/cpu-freq | 5 ++++ bin/date | 4 ++++ bin/ec2-cost | 2 -- bin/hostname | 5 ++++ bin/load-average | 5 ++++ bin/logo | 41 +++++++++++++++++++++++---------- bin/mem-available | 5 ++++ bin/mem-used | 5 ++++ bin/menu | 2 ++ bin/network-down | 5 ++++ bin/network-up | 5 ++++ bin/processes | 5 ++++ bin/reboot-required | 5 ++++ bin/release | 8 +++++++ bin/time | 5 ++++ bin/updates-available | 7 ++++++ bin/uptime | 5 ++++ bin/users | 5 ++++ bin/whoami | 5 ++++ bin/wifi-quality | 6 +++++ debian/changelog | 10 +++++++- debian/install | 1 + debian/rules | 2 +- keybindings/common | 1 + screen-profiles-status | 12 ++++++++++ screen-profiles-status-detail.1 | 15 ++++++++++++ 29 files changed, 177 insertions(+), 16 deletions(-) create mode 100644 screen-profiles-status-detail.1 diff --git a/bin/arch b/bin/arch index 890ed900..128eb0c1 100755 --- a/bin/arch +++ b/bin/arch @@ -17,4 +17,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ "$1" = "--detail" ]; then + uname -a + exit 0 +fi + printf "%s " $(uname -m) diff --git a/bin/battery b/bin/battery index c42c7de6..cd2f586f 100755 --- a/bin/battery +++ b/bin/battery @@ -31,6 +31,14 @@ search () { BATS=$(ls /proc/acpi/battery) NB=$(echo "$BATS" | wc -l) +if [ "$1" = "--detail" ]; then + for bat in $BATS; do + cat "/proc/acpi/battery/$bat/info" + cat "/proc/acpi/battery/$bat/state" + done + exit 0 +fi + for bat in $BATS; do if [ "$NB" -gt 1 ]; then echo -n "$bat: " diff --git a/bin/cpu-count b/bin/cpu-count index 4f9a8317..5f4f9b9a 100755 --- a/bin/cpu-count +++ b/bin/cpu-count @@ -19,3 +19,7 @@ count=`grep -c "^processor.*:" /proc/cpuinfo` [ "$count" = "1" ] || echo $count"x" +if [ "$1" = "--detail" ]; then + echo + exit 0 +fi diff --git a/bin/cpu-freq b/bin/cpu-freq index d89b3a05..d3be570a 100755 --- a/bin/cpu-freq +++ b/bin/cpu-freq @@ -17,6 +17,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ "$1" = "--detail" ]; then + cat /proc/cpuinfo + exit 0 +fi + mhz=`egrep -i -m 1 "^cpu MHz|^clock|^bogomips" /proc/cpuinfo | awk -F"[:.]" '{print $2}'` speed=$(echo $mhz | awk '{ printf "%.1f", $1 / 1000 }') diff --git a/bin/date b/bin/date index 32cba302..803a563f 100755 --- a/bin/date +++ b/bin/date @@ -17,4 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ "$1" = "--detail" ]; then + date + exit 0 +fi printf "\005Y-\005m-\005d " diff --git a/bin/ec2-cost b/bin/ec2-cost index 5980f288..3238f4b5 100755 --- a/bin/ec2-cost +++ b/bin/ec2-cost @@ -78,7 +78,6 @@ uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$CPU_RATE" * $hours}"` total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "~\$%.2f", $1 + $2}'` if [ "$DETAIL" = "1" ]; then - echo echo "================================================" echo "Estimated cost in Amazon's EC2 since last reboot" echo "================================================" @@ -91,7 +90,6 @@ if [ "$DETAIL" = "1" ]; then echo "------------------------------------------------" echo "Total cost: $total_cost" echo "================================================" - echo exit 0 fi diff --git a/bin/hostname b/bin/hostname index 6e67b95b..6c0fb0d4 100755 --- a/bin/hostname +++ b/bin/hostname @@ -17,6 +17,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ "$1" = "--detail" ]; then + hostname -f + exit 0 +fi + at= grep -qs "^whoami=1$" "$HOME/.screen-profiles/status" && at="@" diff --git a/bin/load-average b/bin/load-average index b0e49fe8..c79278f2 100755 --- a/bin/load-average +++ b/bin/load-average @@ -17,4 +17,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ "$1" = "--detail" ]; then + cat /proc/loadavg + exit 0 +fi + printf "\005{= Yk}%s\005{-} " $(cat /proc/loadavg | cut -d " " -f -1) diff --git a/bin/logo b/bin/logo index 2f48a3d5..9ca310a6 100755 --- a/bin/logo +++ b/bin/logo @@ -17,32 +17,49 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ "$1" = "--detail" ]; then + MARKUP="false" +else + MARKUP="true" +fi + print_logo() { distro="$1" if echo "$distro" | grep -qsi "ubuntu"; then - printf "\005{=b kr}\\\\\005{= ky}o\005{=b kY}/" + $MARKUP && printf "\005{=b kr}\\\\\005{= ky}o\005{=b kY}/" || printf "\\o/" elif echo "$distro" | grep -qsi "arch"; then - printf "\005{=b wb} A " + logo=" A " + $MARKUP && printf "\005{=b wb}$logo" || printf "$logo" elif echo "$distro" | grep -qsi "centos"; then - printf "\005{= gw}*\005{= mw}*\005{= yw}*\005{= bw}*%{=b Wk}" + logo="****" + $MARKUP && printf "\005{= gw}*\005{= mw}*\005{= yw}*\005{= bw}*%{=b Wk}" || printf "$logo" elif echo "$distro" | grep -qsi "debian"; then - printf "\005{= wr} @ " + logo=" @ " + $MARKUP && printf "\005{= wr}$logo" || printf "$logo" elif echo "$distro" | grep -qsi "fedora"; then - printf "\005{=b bw} f " + logo=" f " + $MARKUP && printf "\005{=b bw}$logo" || printf "$logo" elif echo "$distro" | grep -qsi "foresight"; then - printf "\005{=b Wg}<@>" + logo="<@>" + $MARKUP && printf "\005{=b Wg}$logo" || printf "$logo" elif echo "$distro" | grep -qsi "gentoo"; then - printf "\005{=b cw} > " + logo=" > " + $MARKUP && printf "\005{=b cw}$logo" || printf "$logo" elif echo "$distro" | grep -qsi "mandriva"; then - printf "\005{=b kc} (\005{=b ky}* " + logo=" (* " + $MARKUP && printf "\005{=b kc} (\005{=b ky}* " || printf "$logo" elif echo "$distro" | grep -qsi "redhat"; then - printf "\005{= Rk} RH " + logo=" RH " + $MARKUP && printf "\005{= Rk}$logo" || printf "$logo" elif echo "$distro" | grep -qsi "slackware"; then - printf "\005{=u Bk},S " + logo=",S " + $MARKUP && printf "\005{=u Bk}$logo" || printf "$logo" elif echo "$distro" | grep -qsi "suse"; then - printf "\005{= Wg}SuSE" + logo="SuSE" + $MARKUP && printf "\005{= Wg}$logo" || printf "$logo" elif echo "$distro" | grep -qsi "xandros"; then - printf "\005{= Wr} X " + logo=" X " + $MARKUP && printf "\005{= Wr}$logo" || printf "$logo" else false fi diff --git a/bin/mem-available b/bin/mem-available index 13db8c45..c021a210 100755 --- a/bin/mem-available +++ b/bin/mem-available @@ -17,6 +17,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ "$1" = "--detail" ]; then + free + exit 0 +fi + comma= whitespace= if [ -r "$HOME/.screen-profiles/status" ]; then diff --git a/bin/mem-used b/bin/mem-used index a0901467..d5a50240 100755 --- a/bin/mem-used +++ b/bin/mem-used @@ -17,4 +17,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ "$1" = "--detail" ]; then + cat /proc/meminfo + exit 0 +fi + free | awk '/buffers\/cache:/ {printf "\005{= gW}%.0f%%\005{-} ", 100*$3/($3 + $4)}' diff --git a/bin/menu b/bin/menu index a46c6315..1f394049 100755 --- a/bin/menu +++ b/bin/menu @@ -17,4 +17,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +[ "$1" = "--detail" ] && exit 0 + printf " \005{= kw}%s" `gettext "Menu:"` diff --git a/bin/network-down b/bin/network-down index 1d5f2847..c56f5db6 100755 --- a/bin/network-down +++ b/bin/network-down @@ -21,6 +21,11 @@ cache="$HOME/.screen-profiles/network-down" interface=`/sbin/route -n | tail -n 1 | sed "s/^.* //"` unit="kB/s" +if [ "$1" = "--detail" ]; then + ifconfig "$interface" + exit 0 +fi + t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0 t2=`date +%s` diff --git a/bin/network-up b/bin/network-up index a27dc9e9..f74bc9d2 100755 --- a/bin/network-up +++ b/bin/network-up @@ -22,6 +22,11 @@ cache="$HOME/.screen-profiles/network-up" interface=`/sbin/route -n | tail -n 1 | sed "s/^.* //"` unit="kB/s" +if [ "$1" = "--detail" ]; then + ifconfig "$interface" + exit 0 +fi + t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0 t2=`date +%s` diff --git a/bin/processes b/bin/processes index e93e0a24..3689bbe2 100755 --- a/bin/processes +++ b/bin/processes @@ -17,4 +17,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ "$1" = "--detail" ]; then + ps -ejH + exit 0 +fi + printf "\005{= yk}%s&\005{-} " $(ps -e | wc -l) diff --git a/bin/reboot-required b/bin/reboot-required index 9a57b37a..67dc5a10 100755 --- a/bin/reboot-required +++ b/bin/reboot-required @@ -17,4 +17,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ "$1" = "--detail" ]; then + [ -e /var/run/reboot-required ] && printf "Yes" || printf "No" + exit 0 +fi + [ -e /var/run/reboot-required ] && printf "\005{=b bW}(@)\005{-} " diff --git a/bin/release b/bin/release index 8b583b70..6570ddb1 100755 --- a/bin/release +++ b/bin/release @@ -18,6 +18,10 @@ # along with this program. If not, see . if which lsb_release >/dev/null; then + if [ "$1" = "--detail" ]; then + lsb_release -a 2>/dev/null + exit 0 + fi # If lsb_release is available, use it r=$(lsb_release -s -d) if echo "$r" | grep -qs "^Ubuntu .*\..*\..*$"; then @@ -31,6 +35,10 @@ if which lsb_release >/dev/null; then printf "\005{=b }%s %s\005{-} " "$i" "$r" fi elif [ -r "/etc/issue" ]; then + if [ "$1" = "--detail" ]; then + cat /etc/issue + exit 0 + fi # Otherwise, grab part of /etc/issue printf "\005{=b }%s\005{-} " $(head -n1 /etc/issue | awk '{print $1}') else diff --git a/bin/time b/bin/time index 85cf8673..889e053a 100755 --- a/bin/time +++ b/bin/time @@ -17,4 +17,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ "$1" = "--detail" ]; then + date + exit 0 +fi + printf "\0050c:\005s" diff --git a/bin/updates-available b/bin/updates-available index 8e86cb76..4836f286 100755 --- a/bin/updates-available +++ b/bin/updates-available @@ -17,6 +17,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ "$1" = "--detail" ]; then + if [ -x "/usr/bin/apt-get" ]; then + /usr/bin/apt-get -s -o Debug::NoLocking=true upgrade | grep ^Inst + fi + exit 0 +fi + # expire the cache in X seconds; 1 hour by default EXPIRATION=3600 diff --git a/bin/uptime b/bin/uptime index 9145a8ff..a3fc7dbd 100755 --- a/bin/uptime +++ b/bin/uptime @@ -20,6 +20,11 @@ # along with this program. If not, see . # +if [ "$1" = "--detail" ]; then + uptime + exit 0 +fi + u=$(sed "s/\..*$//" /proc/uptime) printf "\005{= wb}" if [ "$u" -gt 86400 ]; then diff --git a/bin/users b/bin/users index 54f5a99e..27d177eb 100755 --- a/bin/users +++ b/bin/users @@ -20,4 +20,9 @@ # along with this program. If not, see . # +if [ "$1" = "--detail" ]; then + who + exit 0 +fi + printf "\005{= wr}%d#\005{-} " `who | wc -l` diff --git a/bin/whoami b/bin/whoami index 20d136f0..2b916d85 100755 --- a/bin/whoami +++ b/bin/whoami @@ -17,4 +17,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +if [ "$1" = "--detail" ]; then + whoami + exit 0 +fi + printf "\005{=b }%s\005{-}" $(whoami) diff --git a/bin/wifi-quality b/bin/wifi-quality index 31a11463..6bd230c4 100755 --- a/bin/wifi-quality +++ b/bin/wifi-quality @@ -18,6 +18,12 @@ # along with this program. If not, see . interface=`/sbin/route -n | tail -n 1 | sed "s/^.* //"` + +if [ "$1" = "--detail" ]; then + iwconfig 2>/dev/null + exit 0 +fi + bitrate=`iwconfig "$interface" 2>/dev/null | grep "Bit Rate." | sed "s/^.*Bit Rate.//" | sed "s/ .*$//g"` [ -z "$bitrate" ] && bitrate="0" quality=`iwconfig "$interface" 2>/dev/null | grep "Link Quality=" | sed "s/^.*Link Quality=//" | sed "s/ .*$//g"` diff --git a/debian/changelog b/debian/changelog index a97f42b5..7fd5f9ae 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,7 +4,15 @@ screen-profiles (1.51) unreleased; urgency=low * bin/hostname: hostname -s fails sometimes, it seems * screen: respect $SCREENRC environment variable, LP: #367250 - -- Dustin Kirkland Sun, 26 Apr 2009 12:07:41 -0500 + Detailed status + * bin/*: add special actions if --detail is specified; basically, + print all relevant information on stdout without formatting + * screen-profiles-status: add support for --detail, loop through + all status scripts with --detail specified + * screen-profiles-status-detail: wrapper using sensible-pager + * screen-profiles-status-detail.1: documentation added + + -- Dustin Kirkland Mon, 27 Apr 2009 21:10:40 -0500 screen-profiles (1.50-0ubuntu1) jaunty; urgency=low diff --git a/debian/install b/debian/install index a29a340d..e9e0ef00 100644 --- a/debian/install +++ b/debian/install @@ -12,6 +12,7 @@ screen usr/bin select-screen-profile usr/bin screen-profiles usr/bin screen-profiles-status usr/bin +screen-profiles-status-detail usr/bin screen-launcher-install usr/share/screen-profiles screen-launcher-uninstall usr/share/screen-profiles motd+shell usr/bin diff --git a/debian/rules b/debian/rules index 100c9bda..e3f73e1c 100755 --- a/debian/rules +++ b/debian/rules @@ -57,7 +57,7 @@ binary-indep: build install dh_testdir -i dh_testroot -i dh_installdocs -X.bzr -i - dh_installman -i screen-launcher.1 screen-profiles.1 select-screen-profile.1 motd+shell.1 screen-profiles-export.1 screen-profiles-status.1 + dh_installman -i screen-launcher.1 screen-profiles.1 select-screen-profile.1 motd+shell.1 screen-profiles-export.1 screen-profiles-status.1 screen-profiles-status-detail.1 dh_installchangelogs -i dh_installdebconf -i dh_compress -i diff --git a/keybindings/common b/keybindings/common index 9a4870c4..ff3b9ab3 100644 --- a/keybindings/common +++ b/keybindings/common @@ -45,3 +45,4 @@ bindkey -k k9 screen -t help 0 screen-profiles # F9 | Configuration # F10 | 'toolbar' in gnome-terminal # F11 | 'fullscreen' in gnome-terminal bindkey -k F2 lockscreen # F12 | Lock this terminal +bind $ screen -t status 0 screen-profiles-status-detail # ctrl-a $ | show detailed status diff --git a/screen-profiles-status b/screen-profiles-status index 9e14c1eb..951f9b06 100755 --- a/screen-profiles-status +++ b/screen-profiles-status @@ -45,6 +45,18 @@ case "$P" in arch|battery|ec2-cost|hostname|network-down|network-up|processes|users|whoami|wifi-quality) grep -qs -m1 "^$P=1$" "$HOME/.screen-profiles/status" || exit 0 ;; + --detail) + for i in `ls "$DIR"`; do + [ "$i" = "menu" ] && continue + echo + echo " ______________________________________________________________________" + echo "/ * $i:" + out=`"$DIR"/$i --detail` + echo "$out" | sed "s/^/| /g" + echo "\\______________________________________________________________________" + done + exit 0 + ;; *) exit 1 ;; diff --git a/screen-profiles-status-detail.1 b/screen-profiles-status-detail.1 new file mode 100644 index 00000000..4fc9176e --- /dev/null +++ b/screen-profiles-status-detail.1 @@ -0,0 +1,15 @@ +.TH screen-profiles-status-detail 1 "27 Apr 2009" screen-profiles "screen-profiles" +.SH NAME +screen\-profiles\-status\-detail \- Wrapper that uses a sensible pager + +.SH DESCRIPTION +\fBscreen\-profiles\-status\-detail\fP is a simple script that uses a sensible pager for displaying the detailed status of all screen\-profiles status scripts. + +.TP +\fIhttp://launchpad.net/screen-profiles\fP +.PD + +.SH AUTHOR +This manpage and the utility was written by Dustin Kirkland for Ubuntu systems (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 3 published by the Free Software Foundation. + +On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL.