diff options
author | not pua <140790944+im-notpua@users.noreply.github.com> | 2023-09-02 11:46:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-02 13:46:59 +0200 |
commit | 0dc40e88a3f5bbe2607d958b5f0bf79e9df0c118 (patch) | |
tree | c0c5d5387013e8b0ba0fc54fbf30d2c558f91b9a /plugins/battery | |
parent | ccce2e1cfdf5b9680f691a402e288d9cf6ce272a (diff) | |
download | zsh-0dc40e88a3f5bbe2607d958b5f0bf79e9df0c118.tar.gz zsh-0dc40e88a3f5bbe2607d958b5f0bf79e9df0c118.tar.bz2 zsh-0dc40e88a3f5bbe2607d958b5f0bf79e9df0c118.zip |
feat(battery): add support for OpenBSD (#11872)
Diffstat (limited to 'plugins/battery')
-rw-r--r-- | plugins/battery/battery.plugin.zsh | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index db5eeb93a..1d3d529a3 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -13,6 +13,10 @@ # Author: Avneet Singh (kalsi-avneet) # # Modified to add support for Android # ########################################### +# Author: Not Pua (im-notpua) # +# Modified to add support for OpenBSD # +########################################### + if [[ "$OSTYPE" = darwin* ]]; then function battery_is_charging() { @@ -139,6 +143,46 @@ elif [[ "$OSTYPE" = linux-android ]] && (( ${+commands[termux-battery-status]} ) echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}" fi } +elif [[ "$OSTYPE" = openbsd* ]]; then + function battery_is_charging() { + [[ $(apm -b) -eq 3 ]] + } + function battery_pct() { + apm -l + } + function battery_pct_remaining() { + if ! battery_is_charging; then + battery_pct + else + echo "External Power" + fi + } + function battery_time_remaining() { + local remaining_time + remaining_time=$(apm -m) + if [[ $remaining_time -ge 0 ]]; then + ((hour = $remaining_time / 60 )) + ((minute = $remaining_time % 60 )) + printf %02d:%02d $hour $minute + fi + } + function battery_pct_prompt() { + local battery_pct color + battery_pct=$(battery_pct_remaining) + if battery_is_charging; then + echo "∞" + else + if [[ $battery_pct -gt 50 ]]; then + color='green' + elif [[ $battery_pct -gt 20 ]]; then + color='yellow' + else + color='red' + fi + echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}" + fi + } + elif [[ "$OSTYPE" = linux* ]]; then function battery_is_charging() { if (( $+commands[acpitool] )); then |