Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Battery time remaining until fully charged indicator #140

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ Enable high contrast pane border
set -g @dracula-border-contrast true
```

#### battery options

Customize label

```bash
set -g @dracula-battery-label "♥"
```

(macOS only) Show time remaining until fully charged

```bash
set -g @dracula-battery-show-charging-time true
```

#### cpu-usage options

Customize label
Expand Down Expand Up @@ -164,13 +178,13 @@ set -g @dracula-git-disable-status true

Set symbol to use for when branch is up to date with HEAD
```bash
# default is ✓. Avoid using non unicode characters that bash uses like $, * and !
# default is ✓. Avoid using non unicode characters that bash uses like $, * and !
set -g @dracula-git-show-current-symbol ✓
```

Set symbol to use for when branch diverges from HEAD
```bash
# default is unicode !. Avoid bash special characters
# default is unicode !. Avoid bash special characters
set -g @dracula-git-show-diff-symbol !
```

Expand All @@ -188,4 +202,3 @@ Switch from default fahrenheit to celsius
```bash
set -g @dracula-show-fahrenheit false
```

39 changes: 36 additions & 3 deletions scripts/battery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8

current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh

IFS=' ' read -r -a show_charging_time <<< $(get_tmux_option "@dracula-battery-show-charging-time" "false")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this into dracula.tmux

Copy link
Author

@Andaar Andaar Sep 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (sorry for almost a year, but I had no time before).


linux_acpi() {
arg=$1
BAT=$(ls -d /sys/class/power_supply/BAT* | head -1)
Expand Down Expand Up @@ -58,6 +63,32 @@ battery_percent()
esac
}

battery_time_left()
{
# Check OS
case $(uname -s) in
Darwin) # regex test: https://regex101.com/r/yU4wn9/1
time=$(pmset -g batt | \
grep -Eo '((([1-9][0-9]*|[1-9]):[0-5][0-9])|(0:[1-5][0-9])|(0:0[1-9]))')
;;
Linux|FreeBSD)
# leaving empty - TODO
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
# leaving empty - TODO - windows compatability
;;
*)
;;
esac
if ! $show_charging_time; then
echo ''
elif [ -z "$time" ]; then
echo ''
else
echo "($time)"
fi
}

battery_status()
{
# Check OS
Expand Down Expand Up @@ -111,16 +142,18 @@ main()
bat_label=$(get_tmux_option "@dracula-battery-label" "♥")
bat_stat=$(battery_status)
bat_perc=$(battery_percent)
bat_time=$(battery_time_left)

if [ -z "$bat_stat" ]; then # Test if status is empty or not
if [ -z "$bat_stat"]; then # Test if status is empty or not
echo "$bat_label $bat_perc"
elif [ -z "$bat_perc" ]; then # In case it is a desktop with no battery percent, only AC power
echo "$bat_label $bat_stat"
else
elif [ -z "$bat_time" ]; then # Battery is fully charged
echo "$bat_label $bat_stat $bat_perc"
else
echo "$bat_label $bat_stat $bat_perc $bat_time"
fi
}

#run main driver program
main