From 8e089ceca6fb57a8c5f2bdc7def871f2ea2250c1 Mon Sep 17 00:00:00 2001 From: Igor Kozub Date: Thu, 4 Nov 2021 01:13:11 +0100 Subject: [PATCH 1/4] Battery charging time left (Darwin only) --- scripts/battery.sh | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/scripts/battery.sh b/scripts/battery.sh index c9d96d7a..e4ba6b1e 100755 --- a/scripts/battery.sh +++ b/scripts/battery.sh @@ -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") + linux_acpi() { arg=$1 BAT=$(ls -d /sys/class/power_supply/BAT* | head -1) @@ -58,6 +63,32 @@ battery_percent() esac } +battery_time_left() +{ + # Check OS + case $(uname -s) in + Darwin) # regex test: https://regex101.com/r/Yju8Wa/1 + time=$(pmset -g batt | \ + grep -Eo '([1-9][0-9]:[0-5][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 @@ -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 - From fabd1cf55541c9271421d31c74627884b79db551 Mon Sep 17 00:00:00 2001 From: Andaar Date: Sun, 7 Nov 2021 20:37:52 +0100 Subject: [PATCH 2/4] Updated battery time regex and INSTALL.md file --- INSTALL.md | 19 ++++++++++++++++--- scripts/battery.sh | 4 ++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index f6e915e7..24788829 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -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 @@ -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 ! ``` @@ -188,4 +202,3 @@ Switch from default fahrenheit to celsius ```bash set -g @dracula-show-fahrenheit false ``` - diff --git a/scripts/battery.sh b/scripts/battery.sh index e4ba6b1e..b3b3588c 100755 --- a/scripts/battery.sh +++ b/scripts/battery.sh @@ -67,9 +67,9 @@ battery_time_left() { # Check OS case $(uname -s) in - Darwin) # regex test: https://regex101.com/r/Yju8Wa/1 + Darwin) # regex test: https://regex101.com/r/yU4wn9/1 time=$(pmset -g batt | \ - grep -Eo '([1-9][0-9]:[0-5][0-9]|[1-9]:[0-5][0-9]|0:[1-5][0-9]|0:0[1-9])') + 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 From d93658f1b61056c754e0707d5434f6f041947aa4 Mon Sep 17 00:00:00 2001 From: Andaar Date: Mon, 19 Sep 2022 17:05:38 +0300 Subject: [PATCH 3/4] small fix --- INSTALL.md | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index aeaf6c2d..3ef9e101 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -111,20 +111,6 @@ 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 @@ -150,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 From 301d0e31c4dac5c54dba2e84d879a497960ee6a4 Mon Sep 17 00:00:00 2001 From: Andaar Date: Mon, 19 Sep 2022 17:06:51 +0300 Subject: [PATCH 4/4] fix --- scripts/battery.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/battery.sh b/scripts/battery.sh index 9fc77354..508f808e 100755 --- a/scripts/battery.sh +++ b/scripts/battery.sh @@ -143,7 +143,7 @@ main() bat_time=$(battery_time_left) if [ -z "$bat_stat" ]; then # Test if status is empty or not - echo "$bat_label $bat_perc $bat_stat" + 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" elif [ -z "$bat_time" ]; then # Battery is fully charged