6095fe4f7157ba444addaf436f9f44e3d491a784
- Author
- Peter Hoeg <p.hoeg@northwind.sg>
- Committer
- Peter Hoeg <p.hoeg@northwind.sg>
- Date
Message
add: battery plugin
Diff
1diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh
2new file mode 100644
3index 0000000000000000000000000000000000000000..bc75c5cf9ad01bd58ef29c4d83782ce5a849baff
4--- /dev/null
5+++ b/plugins/battery/battery.plugin.zsh
6@@ -0,0 +1,20 @@
7+if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
8+ function battery_pct_remaining() { echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" }
9+ function battery_time_remaining() { echo $(acpi | cut -f3 -d ',') }
10+ function battery_pct_prompt() {
11+ b=$(battery_pct_remaining)
12+ if [ $b -gt 50 ] ; then
13+ color='green'
14+ elif [ $b -gt 20 ] ; then
15+ color='yellow'
16+ else
17+ color='red'
18+ fi
19+ echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}"
20+ }
21+else
22+ error_msg='no battery'
23+ function battery_pct_remaining() { echo $error_msg }
24+ function battery_time_remaining() { echo $error_msg }
25+ function battery_pct_prompt() { echo '' }
26+fi