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 all 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
10 changes: 8 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ Customize label
set -g @dracula-battery-label "Battery"
```

(macOS only) Show time remaining until fully charged

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

#### gpu-usage options

Customize label
Expand Down Expand Up @@ -190,13 +196,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 Down
32 changes: 30 additions & 2 deletions scripts/battery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,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 @@ -114,16 +140,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
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

3 changes: 2 additions & 1 deletion scripts/dracula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ main()
show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false)
show_day_month=$(get_tmux_option "@dracula-day-month" false)
show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5)
show_charging_time=$(get_tmux_option "@dracula-battery-show-charging-time" "false")
IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather")

# Dracula Color Pallette
Expand Down Expand Up @@ -129,7 +130,7 @@ main()

if [ $plugin = "git" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray")
script="#($current_dir/git.sh)"
script="#($current_dir/git.sh)"
fi

if [ $plugin = "battery" ]; then
Expand Down