1
0
Fork 0
mirror of synced 2024-12-22 06:41:07 -05:00

split _battery() into _battery_status() and _battery_bar() to refresh #{battery_status} more quickly

This commit is contained in:
Gregory Pakosz 2019-09-22 15:40:35 +02:00
parent 89bc03c612
commit d6ea9ad9c7
2 changed files with 35 additions and 15 deletions

View file

@ -254,7 +254,7 @@ run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-tim
# display "mouse: $new" # display "mouse: $new"
# } # }
# #
# _battery() { # _battery_info() {
# count=0 # count=0
# charge=0 # charge=0
# case "$_uname_s" in # case "$_uname_s" in
@ -301,7 +301,7 @@ run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-tim
# charge=$(printf '%s' "$line" | awk -v charge="$charge" '{ print charge + $2 / 100 }') # charge=$(printf '%s' "$line" | awk -v charge="$charge" '{ print charge + $2 / 100 }')
# count=$((count + 1)) # count=$((count + 1))
# done << EOF # done << EOF
# $(wmic path Win32_Battery get BatteryStatus, EstimatedChargeRemaining | tr -d '\r' | tail -n +2) # $(wmic path Win32_Battery get BatteryStatus, EstimatedChargeRemaining 2> /dev/null | tr -d '\r' | tail -n +2 || true)
# EOF # EOF
# ;; # ;;
# *OpenBSD*) # *OpenBSD*)
@ -319,10 +319,31 @@ run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-tim
# done # done
# ;; # ;;
# esac # esac
# [ "$count" -ne 0 ] && charge=$(awk -v charge="$charge" -v count="$count" 'BEGIN { print charge / count }') # [ "$count" -ne 0 ] && charge=$(awk -v charge="$charge" -v count="$count" 'BEGIN { print charge / count }') || true
# if [ "$charge" -eq 0 ]; then # }
# tmux set -ug '@battery_status' \;\ #
# set -ug '@battery_bar' \;\ # _battery_status() {
# _battery_info
# if [ "$charge" = 0 ]; then
# tmux set -ug '@battery_status'
# return
# fi
#
# battery_status_charging=$1
# battery_status_discharging=$2
# if [ x"$discharging" = x"true" ]; then
# battery_status="$battery_status_discharging"
# else
# battery_status="$battery_status_charging"
# fi
#
# tmux set -g '@battery_status' "$battery_status"
# }
#
# _battery_bar() {
# _battery_info
# if [ "$charge" = 0 ]; then
# tmux set -ug '@battery_bar' \;\
# set -ug '@battery_hbar' \;\ # set -ug '@battery_hbar' \;\
# set -ug '@battery_vbar' \;\ # set -ug '@battery_vbar' \;\
# set -ug '@battery_percentage' # set -ug '@battery_percentage'
@ -543,9 +564,9 @@ run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-tim
# ssh_or_mosh_args=$(_ssh_or_mosh_args "$command") # ssh_or_mosh_args=$(_ssh_or_mosh_args "$command")
# if [ -n "$ssh_or_mosh_args" ]; then # if [ -n "$ssh_or_mosh_args" ]; then
# # shellcheck disable=SC2086 # # shellcheck disable=SC2086
# username=$(ssh -G $ssh_or_mosh_args 2>/dev/null | awk 'NR > 2 { exit } ; /^user / { print $2 }') # username=$(command ssh -G $ssh_or_mosh_args 2>/dev/null | awk 'NR > 2 { exit } ; /^user / { print $2 }')
# # shellcheck disable=SC2086 # # shellcheck disable=SC2086
# [ -z "$username" ] && username=$(ssh -T -o ControlPath=none -o ProxyCommand="sh -c 'echo %%username%% %r >&2'" $ssh_or_mosh_args 2>&1 | awk '/^%username% / { print $2; exit }') # [ -z "$username" ] && username=$(command ssh -T -o ControlPath=none -o ProxyCommand="sh -c 'echo %%username%% %r >&2'" $ssh_or_mosh_args 2>&1 | awk '/^%username% / { print $2; exit }')
# else # else
# if ! _is_enabled "$ssh_only"; then # if ! _is_enabled "$ssh_only"; then
# username=$(printf '%s' "$tty_info" | cut -d' ' -f2) # username=$(printf '%s' "$tty_info" | cut -d' ' -f2)
@ -1130,12 +1151,12 @@ run -b '[ -z "#{window_active}" ] && [ -z "#{version}" ] && tmux set display-tim
# set -g '@battery_bar_length' "$tmux_conf_battery_bar_length" \;\ # set -g '@battery_bar_length' "$tmux_conf_battery_bar_length" \;\
# set -g '@battery_bar_palette' "$tmux_conf_battery_bar_palette" \;\ # set -g '@battery_bar_palette' "$tmux_conf_battery_bar_palette" \;\
# set -g '@battery_hbar_palette' "$tmux_conf_battery_hbar_palette" \;\ # set -g '@battery_hbar_palette' "$tmux_conf_battery_hbar_palette" \;\
# set -g '@battery_vbar_palette' "$tmux_conf_battery_vbar_palette" \;\ # set -g '@battery_vbar_palette' "$tmux_conf_battery_vbar_palette"
# set -g '@battery_status_charging' "$(_decode_unicode_escapes "$tmux_conf_battery_status_charging")" \;\ # tmux_conf_battery_status_charging=$(_decode_unicode_escapes "$tmux_conf_battery_status_charging")
# set -g '@battery_status_discharging' "$(_decode_unicode_escapes "$tmux_conf_battery_status_discharging")" # tmux_conf_battery_status_discharging=$(_decode_unicode_escapes "$tmux_conf_battery_status_discharging")
# interval=60 # interval=60
# pkill -f 'cut -c3- ~/\.tmux\.conf \| sh -s _battery' || true # pkill -f 'cut -c3- ~/\.tmux\.conf \| sh -s _battery' || true
# status_right="#(printf '\n'; while [ \$(tmux display -p '##{session_attached}') -gt 0 ]; do nice cut -c3- ~/.tmux.conf | sh -s _battery; sleep $interval; done)$status_right" # status_right="#(printf '\n'; nice cut -c3- ~/.tmux.conf | sh -s _battery_status \"$tmux_conf_battery_status_charging\" \"$tmux_conf_battery_status_discharging\")#(printf '\n'; while [ \$(tmux display -p '##{session_attached}') -gt 0 ]; do nice cut -c3- ~/.tmux.conf | sh -s _battery_bar; sleep $interval; done)$status_right"
# ;; # ;;
# esac # esac
# #

View file

@ -251,9 +251,8 @@ tmux_conf_battery_vbar_palette='gradient'
# symbols used to indicate whether battery is charging or discharging # symbols used to indicate whether battery is charging or discharging
tmux_conf_battery_status_charging='↑' # U+2191 tmux_conf_battery_status_charging='↑' # U+2191
tmux_conf_battery_status_discharging='↓' # U+2193 tmux_conf_battery_status_discharging='↓' # U+2193
#tmux_conf_battery_status_charging='⚡ ' # U+26A1 #tmux_conf_battery_status_charging='🔌' # U+1F50C
#tmux_conf_battery_status_charging='🔌 ' # U+1F50C #tmux_conf_battery_status_discharging='🔋' # U+1F50B
#tmux_conf_battery_status_discharging='🔋 ' # U+1F50B
# clock style (when you hit <prefix> + t) # clock style (when you hit <prefix> + t)
# you may want to use %I:%M %p in place of %R in tmux_conf_theme_status_right # you may want to use %I:%M %p in place of %R in tmux_conf_theme_status_right