Browse code

Merge pull request #669 from peterhoeg/f/battery

add: battery plugin

Robby Russell authored on 26/12/2011 at 18:29:14
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,20 @@
0
+if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
1
+  function battery_pct_remaining() { echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" }
2
+  function battery_time_remaining() { echo $(acpi | cut -f3 -d ',') }
3
+  function battery_pct_prompt() {
4
+    b=$(battery_pct_remaining)
5
+    if [ $b -gt 50 ] ; then
6
+      color='green'
7
+    elif [ $b -gt 20 ] ; then
8
+      color='yellow'
9
+    else
10
+      color='red'
11
+    fi
12
+    echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}"
13
+  }
14
+else
15
+  error_msg='no battery'
16
+  function battery_pct_remaining() { echo $error_msg }
17
+  function battery_time_remaining() { echo $error_msg }
18
+  function battery_pct_prompt() { echo '' }
19
+fi