0dc40e88a3f5bbe2607d958b5f0bf79e9df0c118
- Author
- not pua <140790944+im-notpua@users.noreply.github.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
feat(battery): add support for OpenBSD (#11872)
Diff
1diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh
2index db5eeb93a700f8c099a05d2ac37d3df051df5cdb..1d3d529a319e9f166ba32e6cf2bc0ec07bb21f6c 100644
3--- a/plugins/battery/battery.plugin.zsh
4+++ b/plugins/battery/battery.plugin.zsh
5@@ -13,6 +13,10 @@
6 # Author: Avneet Singh (kalsi-avneet) #
7 # Modified to add support for Android #
8 ###########################################
9+# Author: Not Pua (im-notpua) #
10+# Modified to add support for OpenBSD #
11+###########################################
12+
13
14 if [[ "$OSTYPE" = darwin* ]]; then
15 function battery_is_charging() {
16@@ -139,6 +143,46 @@ elif [[ "$OSTYPE" = linux-android ]] && (( ${+commands[termux-battery-status]} )
17 echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}"
18 fi
19 }
20+elif [[ "$OSTYPE" = openbsd* ]]; then
21+ function battery_is_charging() {
22+ [[ $(apm -b) -eq 3 ]]
23+ }
24+ function battery_pct() {
25+ apm -l
26+ }
27+ function battery_pct_remaining() {
28+ if ! battery_is_charging; then
29+ battery_pct
30+ else
31+ echo "External Power"
32+ fi
33+ }
34+ function battery_time_remaining() {
35+ local remaining_time
36+ remaining_time=$(apm -m)
37+ if [[ $remaining_time -ge 0 ]]; then
38+ ((hour = $remaining_time / 60 ))
39+ ((minute = $remaining_time % 60 ))
40+ printf %02d:%02d $hour $minute
41+ fi
42+ }
43+ function battery_pct_prompt() {
44+ local battery_pct color
45+ battery_pct=$(battery_pct_remaining)
46+ if battery_is_charging; then
47+ echo "∞"
48+ else
49+ if [[ $battery_pct -gt 50 ]]; then
50+ color='green'
51+ elif [[ $battery_pct -gt 20 ]]; then
52+ color='yellow'
53+ else
54+ color='red'
55+ fi
56+ echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}"
57+ fi
58+ }
59+
60 elif [[ "$OSTYPE" = linux* ]]; then
61 function battery_is_charging() {
62 if (( $+commands[acpitool] )); then