bin/network-down, bin/network-up: added network transmit status

-Dustin Kirkland <kirkland@ubuntu.com>Sat, 04 Apr 2009 22:44:27 -0700
This commit is contained in:
Dustin Kirkland 2009-04-04 22:45:19 -07:00
commit 53f018df13
9 changed files with 152 additions and 56 deletions

45
bin/network-down Executable file
View file

@ -0,0 +1,45 @@
#!/bin/sh -e
#
# network-down: calculate the network receive rate
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
#
# 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 <http://www.gnu.org/licenses/>.
# 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{-} "

46
bin/network-up Executable file
View file

@ -0,0 +1,46 @@
#!/bin/sh -e
#
# network-up: calculate the network transmit rate
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
#
# 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 <http://www.gnu.org/licenses/>.
# 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{-} "

3
debian/changelog vendored
View file

@ -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 <kirkland@ubuntu.com> Fri, 03 Apr 2009 13:07:57 -0700
-- Dustin Kirkland <kirkland@ubuntu.com> Sat, 04 Apr 2009 22:44:27 -0700
screen-profiles (1.42-0ubuntu1) jaunty; urgency=low

View file

@ -3,13 +3,13 @@
# This file is distributed under the same license as the GNU Screen Profiles package.
# Nicolas Valcarcel <nvalcarcel@ubuntu.com>, 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 <nvalcarcel@ubuntu.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 "<Tab>/<Alt-Tab> between elements | <Return> Validates"
msgstr ""

View file

@ -3,13 +3,13 @@
# This file is distributed under the same license as the GNU Screen Profiles package.
# Nicolas Barcet <nicolas.barcet@ubuntu.com>, 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 <nicolas.barcet@ubuntu.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 "<Tab>/<Alt-Tab> between elements | <Return> Validates"
msgstr ""

View file

@ -3,13 +3,13 @@
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 "<Tab>/<Alt-Tab> between elements | <Return> Validates"
msgstr ""

View file

@ -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

View file

@ -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'.

View file

@ -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