mirror of
https://github.com/tmux-plugins/tmux-battery.git
synced 2026-09-10 07:26:19 -04:00
Add @batt_remain_short variable (#52)
* Remove format string count * Add variable @batt_remain_short Hides output if battery is charging or charged, and shortens the discharging output to ~H:MM.
This commit is contained in:
parent
8fa3b627b6
commit
3d7cfed467
11
README.md
11
README.md
|
|
@ -65,7 +65,7 @@ Battery between 50% and 16% charged:<br/>
|
|||
Battery between 15% and dead:<br/>
|
||||

|
||||
|
||||
This is done by introducing 4 new format strings that can be added to
|
||||
This is done by introducing new format strings that can be added to
|
||||
`status-right` option:
|
||||
- `#{battery_icon}` - will display a battery status icon
|
||||
- `#{battery_percentage}` - will show battery percentage
|
||||
|
|
@ -96,6 +96,15 @@ after you do this.
|
|||
|
||||
*Warning*: The battery icon change most likely will not be instant. When you un-plug the power cord, it will take some time (15 - 60 seconds) for the icon to change. This depends on the `status-interval` tmux option. Setting it to 15 seconds should be good enough.
|
||||
|
||||
## Shortened remaining output
|
||||
|
||||
To shorten the output of `#{battery_remain}`, set the following variable:
|
||||
|
||||
set -g @batt_remain_short true
|
||||
|
||||
This will hide output if the battery is charging or charged, and shorten the
|
||||
time remaining (when discharging) to `~H:MM`.
|
||||
|
||||
### Tmux Plugins
|
||||
|
||||
This plugin is part of the [tmux-plugins](https://github.com/tmux-plugins) organisation. Checkout plugins as [resurrect](https://github.com/tmux-plugins/tmux-resurrect), [logging](https://github.com/tmux-plugins/tmux-logging), [online status](https://github.com/tmux-plugins/tmux-online-status), and many more over at the [tmux-plugins](https://github.com/tmux-plugins) organisation page.
|
||||
|
|
|
|||
|
|
@ -4,6 +4,12 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
short=false
|
||||
|
||||
get_remain_settings() {
|
||||
short=$(get_tmux_option "@batt_remain_short" false)
|
||||
}
|
||||
|
||||
battery_discharging() {
|
||||
local status="$(battery_status)"
|
||||
[[ $status =~ (discharging) ]]
|
||||
|
|
@ -12,13 +18,23 @@ battery_discharging() {
|
|||
pmset_battery_remaining_time() {
|
||||
local status="$(pmset -g batt)"
|
||||
if echo $status | grep 'no estimate' >/dev/null 2>&1; then
|
||||
echo '- Calculating estimate...'
|
||||
if $short; then
|
||||
echo '~?:??'
|
||||
else
|
||||
echo '- Calculating estimate...'
|
||||
fi
|
||||
else
|
||||
local remaining_time="$(echo $status | grep -o '[0-9]\{1,2\}:[0-9]\{1,2\}')"
|
||||
if battery_discharging; then
|
||||
echo $remaining_time | awk '{printf "- %s left", $1}'
|
||||
if $short; then
|
||||
echo $remaining_time | awk '{printf "~%s"}'
|
||||
else
|
||||
echo $remaining_time | awk '{printf "- %s left", $1}'
|
||||
fi
|
||||
else
|
||||
echo $remaining_time | awk '{printf "- %s till full", $1}'
|
||||
if !$short; then
|
||||
echo $remaining_time | awk '{printf "- %s till full", $1}'
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
|
@ -43,6 +59,10 @@ print_battery_remain() {
|
|||
}
|
||||
|
||||
print_battery_full() {
|
||||
if !$short; then
|
||||
return
|
||||
fi
|
||||
|
||||
if command_exists "pmset"; then
|
||||
pmset_battery_remaining_time
|
||||
elif command_exists "upower"; then
|
||||
|
|
@ -52,10 +72,13 @@ print_battery_full() {
|
|||
}
|
||||
|
||||
main() {
|
||||
get_remain_settings
|
||||
if battery_discharging; then
|
||||
print_battery_remain
|
||||
else
|
||||
print_battery_full
|
||||
if !$short; then
|
||||
print_battery_full
|
||||
fi
|
||||
fi
|
||||
}
|
||||
main
|
||||
|
|
|
|||
Loading…
Reference in a new issue