From 1f318a0e23f1ec01095beeff858252f78eeff4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Wed, 1 Apr 2009 17:45:14 +0200 Subject: [PATCH 1/7] Added battery_state to monitor battery state. --- bin/battery_state | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 bin/battery_state diff --git a/bin/battery_state b/bin/battery_state new file mode 100755 index 00000000..02652b0c --- /dev/null +++ b/bin/battery_state @@ -0,0 +1,85 @@ +#!/bin/sh -e +# +# battery_state: print the state of the battery +# Copyright (C) 2009 Raphaël Pinson. +# +# Authors: Raphaël Pinson +# +# 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, either version 3 of the License, or +# (at your option) any later version. +# +# 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 . +# + + +search () { + local str expr + str="$1" + expr="$2" + + echo "$str" | sed -n "s/${expr}/\1/p" +} + + +BATS=$(ls /proc/acpi/battery) +NB=$(echo "$BATS" | wc -l) + +for bat in $BATS; do + if [ "$NB" -gt 1 ]; then + echo -n "$bat: " + fi + + # read files once + infofile=$(cat "/proc/acpi/battery/$bat/info") + statefile=$(cat "/proc/acpi/battery/$bat/state") + + present=$(search "$infofile" "present: *\(.*\)") + + if [ "x${present}" = "xno" ]; then + echo "n/a" + break + fi + + full=$(search "$infofile" "last full capacity: *\(.*\) m[AW]h") + warn=$(search "$infofile" "design capacity warning: \(.*\) m[AW]h") + low=$(search "$infofile" "design capacity low: \(.*\) m[AW]h") + + rem=$(search "$statefile" "remaining capacity: *\(.*\) m[AW]h") + if [ "$rem" -lt "$low" ]; then + alert="! " + elif [ "$rem" -lt "$warn" ]; then + alert="/!\ " + else + alert="" + fi + + percent=$(echo "100*$rem/$full" | bc) + state=$(search "$statefile" "charging state: *\(.*\)") + + case $state in + charging) + sign="+" + ;; + discharging) + sign="-" + ;; + charged) + sign="=" + ;; + *) + sign=" $state" + ;; + esac + + echo "${alert}${percent}%${sign}" +done + + From 6841c9d26bb93d627129f2179d467a7c50b4182c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Wed, 1 Apr 2009 17:47:40 +0200 Subject: [PATCH 2/7] Use colors in alerts in battery_state. --- bin/battery_state | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/battery_state b/bin/battery_state index 02652b0c..6be45a19 100755 --- a/bin/battery_state +++ b/bin/battery_state @@ -54,9 +54,9 @@ for bat in $BATS; do rem=$(search "$statefile" "remaining capacity: *\(.*\) m[AW]h") if [ "$rem" -lt "$low" ]; then - alert="! " + alert="\005{=b .r}! " elif [ "$rem" -lt "$warn" ]; then - alert="/!\ " + alert="\005{= .y}/!\ " else alert="" fi From 8e761ca50cf01b2d00a2fc276fc90df38c8e5b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Wed, 1 Apr 2009 18:11:03 +0200 Subject: [PATCH 3/7] Display "/!\" for both warn and low alert. The color now makes the difference. --- bin/battery_state | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/battery_state b/bin/battery_state index 6be45a19..45c8ad33 100755 --- a/bin/battery_state +++ b/bin/battery_state @@ -54,7 +54,7 @@ for bat in $BATS; do rem=$(search "$statefile" "remaining capacity: *\(.*\) m[AW]h") if [ "$rem" -lt "$low" ]; then - alert="\005{=b .r}! " + alert="\005{=b .r}/!\ " elif [ "$rem" -lt "$warn" ]; then alert="\005{= .y}/!\ " else From 8cd3937ed93904021aa466adc6578318fa6a93d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Wed, 1 Apr 2009 18:25:32 +0200 Subject: [PATCH 4/7] Do not display /!\ since the colors indicate the criticity already --- bin/battery_state | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/battery_state b/bin/battery_state index 45c8ad33..0c8fb6d7 100755 --- a/bin/battery_state +++ b/bin/battery_state @@ -54,9 +54,9 @@ for bat in $BATS; do rem=$(search "$statefile" "remaining capacity: *\(.*\) m[AW]h") if [ "$rem" -lt "$low" ]; then - alert="\005{=b .r}/!\ " + alert="\005{=b .r}" elif [ "$rem" -lt "$warn" ]; then - alert="\005{= .y}/!\ " + alert="\005{= .y}" else alert="" fi From e3bc19b5b5125d8802a3c2bc0c5461698c72ad5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Wed, 1 Apr 2009 18:25:58 +0200 Subject: [PATCH 5/7] Only + is useful: * Battery is discharging unless there is a "+"; * Full is obvious when the percentage reaches 100. --- bin/battery_state | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/bin/battery_state b/bin/battery_state index 0c8fb6d7..6974359f 100755 --- a/bin/battery_state +++ b/bin/battery_state @@ -68,14 +68,8 @@ for bat in $BATS; do charging) sign="+" ;; - discharging) - sign="-" - ;; - charged) - sign="=" - ;; *) - sign=" $state" + sign="" ;; esac From 17f530c2a2521f5847fb05a653151a4aa1f27afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Wed, 1 Apr 2009 18:56:50 +0200 Subject: [PATCH 6/7] Apply the background to an ASCII art battery with a sign in it: * - for discharging * + for charging * = for full Change the background color of the ASCII art battery only to reflect the state: * green: OK * orange: warn * red: low --- bin/battery_state | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/battery_state b/bin/battery_state index 6974359f..2e3e2172 100755 --- a/bin/battery_state +++ b/bin/battery_state @@ -54,13 +54,14 @@ for bat in $BATS; do rem=$(search "$statefile" "remaining capacity: *\(.*\) m[AW]h") if [ "$rem" -lt "$low" ]; then - alert="\005{=b .r}" + color="\005{= r.}" elif [ "$rem" -lt "$warn" ]; then - alert="\005{= .y}" + color="\005{= y.}" else - alert="" + color="\005{= g.}" fi + percent=$(echo "100*$rem/$full" | bc) state=$(search "$statefile" "charging state: *\(.*\)") @@ -68,12 +69,18 @@ for bat in $BATS; do charging) sign="+" ;; + discharging) + sign="-" + ;; + charged) + sign="=" + ;; *) - sign="" + sign="$state" ;; esac - echo "${alert}${percent}%${sign}" + echo "${color}|${sign}|\005{-}${percent}%" done From 5f1598f6ae358806d8f526e1a3709a103e4caf1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Thu, 2 Apr 2009 17:18:17 +0200 Subject: [PATCH 7/7] Added nb-users and uptime scripts. --- bin/nb-users | 23 +++++++++++++++++++++++ bin/uptime | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 bin/nb-users create mode 100755 bin/uptime diff --git a/bin/nb-users b/bin/nb-users new file mode 100755 index 00000000..1fb1c9bc --- /dev/null +++ b/bin/nb-users @@ -0,0 +1,23 @@ +#!/bin/sh -e +# +# nb_users: print the number of users on the machine +# Copyright (C) 2009 Raphaël Pinson. +# +# Authors: Raphaël Pinson +# +# 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, either version 3 of the License, or +# (at your option) any later version. +# +# 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 . +# + +uptime | sed -e "s/.*, *\(.* user[s]*\), .*/\1/" + diff --git a/bin/uptime b/bin/uptime new file mode 100755 index 00000000..c4bb3422 --- /dev/null +++ b/bin/uptime @@ -0,0 +1,23 @@ +#!/bin/sh -e +# +# uptime: condensed uptime of the machine +# Copyright (C) 2009 Raphaël Pinson. +# +# Authors: Raphaël Pinson +# +# 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, either version 3 of the License, or +# (at your option) any later version. +# +# 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 . +# + +uptime | sed -e "s/.* up *\(.*\), *.* user[s]*, .*/\1/; s/ day[s]*, */d/" +