mirror of
https://github.com/tmux-plugins/tmux-battery.git
synced 2026-09-10 07:26:19 -04:00
Merge pull request #6 from asethwright/master
Add battery remaining time interpolation
This commit is contained in:
commit
7002d871c8
|
|
@ -11,10 +11,14 @@ Battery discharging, custom discharge icon:<br/>
|
|||
Battery charging:<br/>
|
||||

|
||||
|
||||
Battery remain:<br/>
|
||||

|
||||
|
||||
This is done by introducing 2 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
|
||||
- `#{battery_remain}` - will show remaining time of battery charge
|
||||
|
||||
### Usage
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,10 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|||
source "$CURRENT_DIR/scripts/helpers.sh"
|
||||
|
||||
battery_percentage="#($CURRENT_DIR/scripts/battery_percentage.sh)"
|
||||
battery_remain="#($CURRENT_DIR/scripts/battery_remain.sh)"
|
||||
battery_icon="#($CURRENT_DIR/scripts/battery_icon.sh)"
|
||||
battery_percentage_interpolation="\#{battery_percentage}"
|
||||
battery_remain_interpolation="\#{battery_remain}"
|
||||
battery_icon_interpolation="\#{battery_icon}"
|
||||
|
||||
set_tmux_option() {
|
||||
|
|
@ -18,7 +20,8 @@ set_tmux_option() {
|
|||
do_interpolation() {
|
||||
local string=$1
|
||||
local percentage_interpolated=${string/$battery_percentage_interpolation/$battery_percentage}
|
||||
local all_interpolated=${percentage_interpolated/$battery_icon_interpolation/$battery_icon}
|
||||
local remain_interpolated=${percentage_interpolated/$battery_remain_interpolation/$battery_remain}
|
||||
local all_interpolated=${remain_interpolated/$battery_icon_interpolation/$battery_icon}
|
||||
echo $all_interpolated
|
||||
}
|
||||
|
||||
|
|
|
|||
BIN
screenshots/battery_remain.png
Normal file
BIN
screenshots/battery_remain.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
19
scripts/battery_remain.sh
Executable file
19
scripts/battery_remain.sh
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
print_battery_remain() {
|
||||
if command_exists "pmset"; then
|
||||
pmset -g batt | awk 'NR==2 { gsub(/;/,""); print $4 }'
|
||||
elif command_exists "upower"; then
|
||||
battery=$(upower -e | grep battery | head -1)
|
||||
upower -i $battery | grep remain | awk '{print $4}'
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
print_battery_remain
|
||||
}
|
||||
main
|
||||
Loading…
Reference in a new issue