From 53f018df1315f046af8bf67383b3aeb68b1f1429 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Sat, 4 Apr 2009 22:45:19 -0700 Subject: [PATCH] bin/network-down, bin/network-up: added network transmit status -Dustin Kirkland Sat, 04 Apr 2009 22:44:27 -0700 --- bin/network-down | 45 +++++++++++++++++++++++++++++++++++++++++ bin/network-up | 46 ++++++++++++++++++++++++++++++++++++++++++ debian/changelog | 3 ++- po/es.po | 36 ++++++++++++++++----------------- po/fr.po | 36 ++++++++++++++++----------------- po/screen-profiles.pot | 36 ++++++++++++++++----------------- profiles/common | 2 ++ profiles/profile.skel | 2 +- screen-profiles | 2 ++ 9 files changed, 152 insertions(+), 56 deletions(-) create mode 100755 bin/network-down create mode 100755 bin/network-up diff --git a/bin/network-down b/bin/network-down new file mode 100755 index 00000000..f63a834a --- /dev/null +++ b/bin/network-down @@ -0,0 +1,45 @@ +#!/bin/sh -e +# +# network-down: calculate the network receive rate +# Copyright (C) 2008 Canonical Ltd. +# +# Authors: Dustin Kirkland +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Default is "off" +p="network-down" +grep -qs "^$p=1$" "$HOME/.screen-profiles/status" || exit 0 + +cache="$HOME/.screen-profiles/$p" +interface=`route -n | tail -n 1 | sed "s/^.* //"` +unit="KB/s" + +t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0 +t2=`date +%s` + +if [ $t2 -le $t1 ]; then + printf "v0 $unit" + exit 0 +fi + +x1=`cat "$cache"` 2>/dev/null || tx1=0 +x2=`ifconfig "$interface" | grep "RX bytes" | sed "s/^.*RX bytes://" | sed "s/ .*$//"` + +echo "$x2" > "$cache" +rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) / 1024 }'` +if [ "$rate" -gt 1024 ]; then + rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'` + unit="MB/s" +fi +printf "\005{= mw}v$rate $unit\005{-} " diff --git a/bin/network-up b/bin/network-up new file mode 100755 index 00000000..0a2a9721 --- /dev/null +++ b/bin/network-up @@ -0,0 +1,46 @@ +#!/bin/sh -e +# +# network-up: calculate the network transmit rate +# Copyright (C) 2008 Canonical Ltd. +# +# Authors: Dustin Kirkland +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Default is "off" +p="network-up" +grep -qs "^$p=1$" "$HOME/.screen-profiles/status" || exit 0 + +cache="$HOME/.screen-profiles/$p" + +interface=`route -n | tail -n 1 | sed "s/^.* //"` +unit="KB/s" + +t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0 +t2=`date +%s` + +if [ $t2 -le $t1 ]; then + printf "v0 $unit" + exit 0 +fi + +x1=`cat "$cache"` 2>/dev/null || tx1=0 +x2=`ifconfig "$interface" | grep "TX bytes" | sed "s/^.*TX bytes://" | sed "s/ .*$//"` + +echo "$x2" > "$cache" +rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) / 1024 }'` +if [ "$rate" -gt 1024 ]; then + rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'` + unit="MB/s" +fi +printf "\005{= mw}^$rate $unit\005{-} " diff --git a/debian/changelog b/debian/changelog index 1c2ffd80..8a08865b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,7 @@ screen-profiles (1.43) unreleased; urgency=low [ Dustin Kirkland ] * bin/logo: allow users to define their own logo * bin/processes: displace a count of the running processes + * bin/network-down, bin/network-up: added network transmit status * bin/*, profiles/profile.skel: make all status scripts handle their own colors and trailing whitespace; this should help alleviate the 16-color-change limitation on un-patched screens; it also simplifies @@ -19,7 +20,7 @@ screen-profiles (1.43) unreleased; urgency=low added new status items for battery state, number of users, and system uptime - -- Dustin Kirkland Fri, 03 Apr 2009 13:07:57 -0700 + -- Dustin Kirkland Sat, 04 Apr 2009 22:44:27 -0700 screen-profiles (1.42-0ubuntu1) jaunty; urgency=low diff --git a/po/es.po b/po/es.po index cf2cfac3..9771da7e 100644 --- a/po/es.po +++ b/po/es.po @@ -3,13 +3,13 @@ # This file is distributed under the same license as the GNU Screen Profiles package. # Nicolas Valcarcel , 2008. # -#: screen-profiles:301 +#: screen-profiles:303 #, fuzzy msgid "" msgstr "" "Project-Id-Version: 1.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-04-03 12:41-0500\n" +"POT-Creation-Date: 2009-04-04 11:09-0700\n" "PO-Revision-Date: 2008-12-22 01:01-0500\n" "Last-Translator: Nicolas Valcarcel \n" "Language-Team: LANGUAGE \n" @@ -57,7 +57,7 @@ msgstr "" msgid "Exit" msgstr "" -#: screen-profiles:87 screen-profiles:467 +#: screen-profiles:87 screen-profiles:469 msgid " Screen Profiles Configuration Menu" msgstr "" @@ -66,14 +66,14 @@ msgid "Okay" msgstr "" #: screen-profiles:98 screen-profiles:134 screen-profiles:150 -#: screen-profiles:185 screen-profiles:308 screen-profiles:350 -#: screen-profiles:428 +#: screen-profiles:185 screen-profiles:310 screen-profiles:352 +#: screen-profiles:430 msgid "Cancel" msgstr "" #: screen-profiles:116 screen-profiles:143 screen-profiles:157 -#: screen-profiles:321 screen-profiles:375 screen-profiles:383 -#: screen-profiles:456 +#: screen-profiles:323 screen-profiles:377 screen-profiles:385 +#: screen-profiles:458 msgid "Menu" msgstr "" @@ -82,7 +82,7 @@ msgid "Screen Profiles Help" msgstr "" #: screen-profiles:134 screen-profiles:150 screen-profiles:185 -#: screen-profiles:308 screen-profiles:350 screen-profiles:428 +#: screen-profiles:310 screen-profiles:352 screen-profiles:430 msgid "Apply" msgstr "" @@ -90,8 +90,8 @@ msgstr "" msgid "Which profile would you like to use?" msgstr "" -#: screen-profiles:142 screen-profiles:156 screen-profiles:320 -#: screen-profiles:382 screen-profiles:454 +#: screen-profiles:142 screen-profiles:156 screen-profiles:322 +#: screen-profiles:384 screen-profiles:456 msgid "Message" msgstr "" @@ -119,35 +119,35 @@ msgstr "" msgid "Create new window(s):" msgstr "" -#: screen-profiles:309 +#: screen-profiles:311 msgid "Toggle status notifications:" msgstr "" -#: screen-profiles:342 +#: screen-profiles:344 msgid "Windows:" msgstr "" -#: screen-profiles:352 +#: screen-profiles:354 msgid "Select window(s) to create by default:" msgstr "" -#: screen-profiles:372 +#: screen-profiles:374 msgid "Screen will be launched automatically next time you login." msgstr "" -#: screen-profiles:380 +#: screen-profiles:382 msgid "Screen will not be used next time you login." msgstr "" -#: screen-profiles:427 +#: screen-profiles:429 msgid "Escape key: ctrl-" msgstr "" -#: screen-profiles:430 +#: screen-profiles:432 msgid "Change escape sequence:" msgstr "" -#: screen-profiles:468 +#: screen-profiles:470 msgid "/ between elements | Validates" msgstr "" diff --git a/po/fr.po b/po/fr.po index 6be18c0c..e4461ef0 100644 --- a/po/fr.po +++ b/po/fr.po @@ -3,13 +3,13 @@ # This file is distributed under the same license as the GNU Screen Profiles package. # Nicolas Barcet , 2008. # -#: screen-profiles:301 +#: screen-profiles:303 #, fuzzy msgid "" msgstr "" "Project-Id-Version: 1.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-04-03 12:41-0500\n" +"POT-Creation-Date: 2009-04-04 11:09-0700\n" "PO-Revision-Date: 2008-12-17 23:42+0100\n" "Last-Translator: Nicolas Barcet \n" "Language-Team: LANGUAGE \n" @@ -57,7 +57,7 @@ msgstr "" msgid "Exit" msgstr "" -#: screen-profiles:87 screen-profiles:467 +#: screen-profiles:87 screen-profiles:469 msgid " Screen Profiles Configuration Menu" msgstr "" @@ -66,14 +66,14 @@ msgid "Okay" msgstr "" #: screen-profiles:98 screen-profiles:134 screen-profiles:150 -#: screen-profiles:185 screen-profiles:308 screen-profiles:350 -#: screen-profiles:428 +#: screen-profiles:185 screen-profiles:310 screen-profiles:352 +#: screen-profiles:430 msgid "Cancel" msgstr "" #: screen-profiles:116 screen-profiles:143 screen-profiles:157 -#: screen-profiles:321 screen-profiles:375 screen-profiles:383 -#: screen-profiles:456 +#: screen-profiles:323 screen-profiles:377 screen-profiles:385 +#: screen-profiles:458 msgid "Menu" msgstr "" @@ -82,7 +82,7 @@ msgid "Screen Profiles Help" msgstr "" #: screen-profiles:134 screen-profiles:150 screen-profiles:185 -#: screen-profiles:308 screen-profiles:350 screen-profiles:428 +#: screen-profiles:310 screen-profiles:352 screen-profiles:430 msgid "Apply" msgstr "" @@ -90,8 +90,8 @@ msgstr "" msgid "Which profile would you like to use?" msgstr "" -#: screen-profiles:142 screen-profiles:156 screen-profiles:320 -#: screen-profiles:382 screen-profiles:454 +#: screen-profiles:142 screen-profiles:156 screen-profiles:322 +#: screen-profiles:384 screen-profiles:456 msgid "Message" msgstr "" @@ -119,35 +119,35 @@ msgstr "" msgid "Create new window(s):" msgstr "" -#: screen-profiles:309 +#: screen-profiles:311 msgid "Toggle status notifications:" msgstr "" -#: screen-profiles:342 +#: screen-profiles:344 msgid "Windows:" msgstr "" -#: screen-profiles:352 +#: screen-profiles:354 msgid "Select window(s) to create by default:" msgstr "" -#: screen-profiles:372 +#: screen-profiles:374 msgid "Screen will be launched automatically next time you login." msgstr "" -#: screen-profiles:380 +#: screen-profiles:382 msgid "Screen will not be used next time you login." msgstr "" -#: screen-profiles:427 +#: screen-profiles:429 msgid "Escape key: ctrl-" msgstr "" -#: screen-profiles:430 +#: screen-profiles:432 msgid "Change escape sequence:" msgstr "" -#: screen-profiles:468 +#: screen-profiles:470 msgid "/ between elements | Validates" msgstr "" diff --git a/po/screen-profiles.pot b/po/screen-profiles.pot index 26eaf2f6..ad4da472 100644 --- a/po/screen-profiles.pot +++ b/po/screen-profiles.pot @@ -3,13 +3,13 @@ # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # -#: screen-profiles:301 +#: screen-profiles:303 #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-04-03 12:41-0500\n" +"POT-Creation-Date: 2009-04-04 11:09-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -57,7 +57,7 @@ msgstr "" msgid "Exit" msgstr "" -#: screen-profiles:87 screen-profiles:467 +#: screen-profiles:87 screen-profiles:469 msgid " Screen Profiles Configuration Menu" msgstr "" @@ -66,14 +66,14 @@ msgid "Okay" msgstr "" #: screen-profiles:98 screen-profiles:134 screen-profiles:150 -#: screen-profiles:185 screen-profiles:308 screen-profiles:350 -#: screen-profiles:428 +#: screen-profiles:185 screen-profiles:310 screen-profiles:352 +#: screen-profiles:430 msgid "Cancel" msgstr "" #: screen-profiles:116 screen-profiles:143 screen-profiles:157 -#: screen-profiles:321 screen-profiles:375 screen-profiles:383 -#: screen-profiles:456 +#: screen-profiles:323 screen-profiles:377 screen-profiles:385 +#: screen-profiles:458 msgid "Menu" msgstr "" @@ -82,7 +82,7 @@ msgid "Screen Profiles Help" msgstr "" #: screen-profiles:134 screen-profiles:150 screen-profiles:185 -#: screen-profiles:308 screen-profiles:350 screen-profiles:428 +#: screen-profiles:310 screen-profiles:352 screen-profiles:430 msgid "Apply" msgstr "" @@ -90,8 +90,8 @@ msgstr "" msgid "Which profile would you like to use?" msgstr "" -#: screen-profiles:142 screen-profiles:156 screen-profiles:320 -#: screen-profiles:382 screen-profiles:454 +#: screen-profiles:142 screen-profiles:156 screen-profiles:322 +#: screen-profiles:384 screen-profiles:456 msgid "Message" msgstr "" @@ -119,34 +119,34 @@ msgstr "" msgid "Create new window(s):" msgstr "" -#: screen-profiles:309 +#: screen-profiles:311 msgid "Toggle status notifications:" msgstr "" -#: screen-profiles:342 +#: screen-profiles:344 msgid "Windows:" msgstr "" -#: screen-profiles:352 +#: screen-profiles:354 msgid "Select window(s) to create by default:" msgstr "" -#: screen-profiles:372 +#: screen-profiles:374 msgid "Screen will be launched automatically next time you login." msgstr "" -#: screen-profiles:380 +#: screen-profiles:382 msgid "Screen will not be used next time you login." msgstr "" -#: screen-profiles:427 +#: screen-profiles:429 msgid "Escape key: ctrl-" msgstr "" -#: screen-profiles:430 +#: screen-profiles:432 msgid "Change escape sequence:" msgstr "" -#: screen-profiles:468 +#: screen-profiles:470 msgid "/ between elements | Validates" msgstr "" diff --git a/profiles/common b/profiles/common index 9652aa08..2bc017f2 100644 --- a/profiles/common +++ b/profiles/common @@ -44,6 +44,8 @@ backtick 113 30 30 /var/lib/screen-profiles/battery backtick 114 10 10 /var/lib/screen-profiles/users backtick 115 60 60 /var/lib/screen-profiles/uptime backtick 116 2 2 /var/lib/screen-profiles/processes +backtick 117 2 2 /var/lib/screen-profiles/network-up +backtick 118 2 2 /var/lib/screen-profiles/network-down hardstatus alwayslastline diff --git a/profiles/profile.skel b/profiles/profile.skel index 6852a698..6bd8a1bf 100644 --- a/profiles/profile.skel +++ b/profiles/profile.skel @@ -26,7 +26,7 @@ source /usr/share/screen-profiles/profiles/common caption always "%{kW}%?%-Lw%?%{bw}%n*%f %t%?(%u)%?%{kW}%?%+Lw%? %= %{= Wk}%110`%109`%111`" # Status string, last line -hardstatus string '%{= Wk}%99`%{= Wk} %100`%112`%102`%101`%= %115`%114`%108`%113`%116`%106`%104`%103`%105`%107`%Y-%m-%d %0c:%s' +hardstatus string '%{= Wk}%99`%{= Wk} %100`%112`%102`%101`%= %115`%114`%108`%113`%116`%117`%118`%106`%104`%103`%105`%107`%Y-%m-%d %0c:%s' # NOTE: Older version of screen have an arbitrary limit of only being able # to change colors 16 times in this 'hardstatus string'. diff --git a/screen-profiles b/screen-profiles index c47a300f..4720c213 100755 --- a/screen-profiles +++ b/screen-profiles @@ -257,6 +257,8 @@ def readstatus(): status["mem-available"]=1 status["mem-used"]=1 status["menu"]=1 + status["network-up"]=0 + status["network-down"]=0 status["processes"]=0 status["reboot-required"]=1 status["release"]=1