Color icon upgrade (#80)

* Upgrade color and icons to have higher granularity

This is a large overhaul of the colors and icons in the plugin to enable
higher granularity. All efforts have been made to have sane defaults.

Additionally, a new 'status' has been added that is a catch-all
'unknown' in case a battery tool acts up or fails to report something
meaningful.

Added 8 new format strings:
* #{battery_color_bg} - will set the background color of the status bar
  based on the battery charge level and status
* #{battery_color_fg} - will set the foreground color of the status bar
  based on the battery charge level and status
* #{battery_color_charge_bg} - will set the background color of the
  status bar based solely on the battery charge level
* #{battery_color_charge_fg} - will set the foreground color of the
  status bar based solely on the battery charge level
* #{battery_color_status_bg} - will set the background color of the
  status bar based solely on the battery status
* #{battery_color_status_fg} - will set the foreground color of the
  status bar based solely on the battery status
* #{battery_icon_charge} - will display a battery charge icon
* #{battery_icon_status} - will display a battery status icon

Removed 2 format strings:
* #{battery_status_bg}
* #{battery_status_fg}

Added 39 new options:
* @batt_color_charge_primary_tier8 - primary color to show at [95%-100%]
  battery charge
* @batt_color_charge_primary_tier7 - primary color to show at [80%-95%)
  battery charge
* @batt_color_charge_primary_tier6 - primary color to show at [65%-90%)
  battery charge
* @batt_color_charge_primary_tier5 - primary color to show at [50%-65%)
  battery charge
* @batt_color_charge_primary_tier4 - primary color to show at [35%-50%)
  battery charge
* @batt_color_charge_primary_tier3 - primary color to show at [20%-35%)
  battery charge
* @batt_color_charge_primary_tier2 - primary color to show at [5%-20%)
  battery charge
* @batt_color_charge_primary_tier1 - primary color to show at [0%-5%)
  battery charge
* @batt_color_charge_secondary_tier8 - secondary color to show at [95%-
  100%] battery charge
* @batt_color_charge_secondary_tier7 - secondary color to show at [80%-
  95%) battery charge
* @batt_color_charge_secondary_tier6 - secondary color to show at [65%-
  90%) battery charge
* @batt_color_charge_secondary_tier5 - secondary color to show at [50%-
  65%) battery charge
* @batt_color_charge_secondary_tier4 - secondary color to show at [35%-
  50%) battery charge
* @batt_color_charge_secondary_tier3 - secondary color to show at [20%-
  35%) battery charge
* @batt_color_charge_secondary_tier2 - secondary color to show at [5%-
  20%) battery charge
* @batt_color_charge_secondary_tier1 - secondary color to show at [0%-
  5%) battery charge
* @batt_color_status_primary_charged - primary color to show for a
  battery in 'fully-charged' status
* @batt_color_status_primary_charging - primary color to show for a
  battery in 'charging' status
* @batt_color_status_primary_discharging - primary color to show for a
  battery in 'discharging' status
* @batt_color_status_primary_attached - primary color to show for a
  battery in 'attached' status
* @batt_color_status_primary_unknown - primary color to show for a
  battery in an unknown status
* @batt_color_status_secondary_charged - secondary color to show for a
  battery in 'fully-charged' status
* @batt_color_status_secondary_charging - secondary color to show for a
  battery in 'charging' status
* @batt_color_status_secondary_discharging - secondary color to show for
  a battery in 'discharging' status
* @batt_color_status_secondary_attached - secondary color to show for a
  battery in 'attached' status
* @batt_color_status_secondary_unknown - secondary color to show for a
  battery in an unknown status
* @batt_icon_charge_tier8 - icon to show at [95%-100%] battery charge
* @batt_icon_charge_tier7 - icon to show at [80%-95%) battery charge
* @batt_icon_charge_tier6 - icon to show at [65%-90%) battery charge
* @batt_icon_charge_tier5 - icon to show at [50%-65%) battery charge
* @batt_icon_charge_tier4 - icon to show at [35%-50%) battery charge
* @batt_icon_charge_tier3 - icon to show at [20%-35%) battery charge
* @batt_icon_charge_tier2 - icon to show at [5%-20%) battery charge
* @batt_icon_charge_tier1 - icon to show at [0%-5%) battery charge
* @batt_icon_status_charged - icon to show for a battery in 'fully-
  charged' status
* @batt_icon_status_charging - icon to show for a battery in 'charging'
  status
* @batt_icon_status_discharging - icon to show for a battery in
  'discharging' status
* @batt_icon_status_attached - icon to show for a battery in 'attached'
  status
* @batt_icon_status_unknown - icon to show for a battery in an unknown
  status

Removed 12 options:
* @batt_charged_icon
* @batt_charging_icon
* @batt_attached_icon
* @batt_full_charge_icon
* @batt_high_charge_icon
* @batt_medium_charge_icon
* @batt_low_charge_icon
* @batt_color_full_charge
* @batt_color_high_charge
* @batt_color_medium_charge
* @batt_color_low_charge
* @batt_color_charging

Format string notes:
* #{battery_color_bg} and #{battery_color_fg} replace
  #{battery_status_bg} and #{battery_status_fg}, respectively and
  continue to act the same way
* #{battery_color_charge_bg/fg} changes colors based ONLY on the battery
  charge level
* #{battery_color_status_bg/fg} changes colors based ONLY on the battery
  status
* #{battery_icon_charge} displays ONLY an icon for the charge level
* #{battery_icon_status} displays ONLY an icon for the charge status
* #{battery_icon} continues to display both

Option notes:
* @batt_color_..._primary options are what will be displayed in the main
  bg or fg you choose - e.g. if you use #{battery_color_bg}, the primary
  color will be the background
* Likewise, the corresponding @batt_color_..._secondary option will be
  the foreground in the example above

* Fixed #{battery_graph} format string

Previously, the #{battery_graph} format string wouldn't show an actual
graph. This has been fixed. The graph is also 5 characters wide now,
regardless of battery charge level.

* Clarified some language in README.md

* Changed a word because words are hard
This commit is contained in:
Dan Cassidy 2019-05-31 07:38:32 -06:00 committed by Martin Beentjes
parent 8e5f5ab4c6
commit 8f1626fe95
36 changed files with 547 additions and 135 deletions

View file

@ -1,6 +1,8 @@
# Changelog
### master
- Fixed `#{battery_graph}` to actually display graph (@rux616)
- High-granularity icons and colors added. (@rux616)
- Changed preferred order of utility applications to be `pmset` -> `acpi` -> `upower` -> `termux-battery-status` due to CPU usage issues with `upower` (2019-03-05) (@rux616)
- Added `#{battery_status_bg}` feature (@RyanFrantz)
- Added multibattery output support for `upower` (@futuro)

231
README.md
View file

@ -9,6 +9,7 @@ In order to read the battery status, this plugin depends on having one of the fo
- acpi
- upower
- termux-battery-status
- apm
In a normal situation, one of the above should be installed on your system by default and thus it should not be necessary to specifically install one of them. That being said, the `acpi` utility is currently recommended for use over `upower` where possible due to ongoing CPU usage issues.
@ -16,9 +17,11 @@ In a normal situation, one of the above should be installed on your system by de
Add plugin to the list of TPM plugins in `.tmux.conf`:
set -g @plugin 'tmux-plugins/tmux-battery'
```tmux
set -g @plugin 'tmux-plugins/tmux-battery'
```
Hit `prefix + I` to fetch the plugin and source it.
Hit `<prefix> + I` to fetch the plugin and source it.
If format strings are added to `status-right`, they should now be visible.
@ -26,95 +29,207 @@ If format strings are added to `status-right`, they should now be visible.
Clone the repo:
$ git clone https://github.com/tmux-plugins/tmux-battery ~/clone/path
```shell
git clone https://github.com/tmux-plugins/tmux-battery ~/clone/path
```
Add this line to the bottom of `.tmux.conf`:
run-shell ~/clone/path/battery.tmux
```tmux
run-shell ~/clone/path/battery.tmux
```
Reload TMUX environment:
From the terminal, reload TMUX environment:
# type this in terminal
$ tmux source-file ~/.tmux.conf
```shell
tmux source-file ~/.tmux.conf
```
If format strings are added to `status-right`, they should now be visible.
## Usage
Add `#{battery_icon}`, `#{battery_percentage}` `#{battery_remain}`, or
`#{battery_status_bg}` format strings to existing `status-right` tmux option.
Example:
Add any of the supported format strings (see below) to the `status-right` tmux option in `.tmux.conf`. Example:
# in .tmux.conf
set -g status-right '#{battery_status_bg} Batt: #{battery_icon} #{battery_percentage} #{battery_remain} | %a %h-%d %H:%M '
```tmux
set -g status-right '#{battery_status_bg} Batt: #{battery_icon} #{battery_percentage} #{battery_remain} | %a %h-%d %H:%M '
```
### Supported Format Strings
## Examples
Battery full (for OS X):<br/>
![battery full](/screenshots/battery_full.png)
- `#{battery_color_bg}` - will set the background color of the status bar based on the battery charge level and status
- `#{battery_color_fg}` - will set the foreground color of the status bar based on the battery charge level and status
- `#{battery_color_charge_bg}` - will set the background color of the status bar based solely on the battery charge level
- `#{battery_color_charge_fg}` - will set the foreground color of the status bar based solely on the battery charge level
- `#{battery_color_status_bg}` - will set the background color of the status bar based solely on the battery status
- `#{battery_color_status_fg}` - will set the foreground color of the status bar based solely on the battery status
- `#{battery_graph}` - will show battery percentage as a bar graph: ▁▂▄▆█
- `#{battery_icon}` - will display a battery status/charge icon
- `#{battery_icon_charge}` - will display a battery charge icon
- `#{battery_icon_status}` - will display a battery status icon
- `#{battery_percentage}` - will show battery percentage
- `#{battery_remain}` - will show remaining time of battery charge\*
Battery discharging, custom discharge icon:<br/>
![battery discharging, custom icon](/screenshots/battery_discharging.png)
\* These format strings can be further customized via options as described below.
Battery charging:<br/>
![battery charging](/screenshots/battery_charging.png)
#### Options
Battery remain:<br/>
![battery remain](/screenshots/battery_remain.png)
`#{battery_remain}`
Battery fully charged:<br/>
![battery_status_bg_green](/screenshots/battery_status_bg_green.png)
- `@batt_remain_short`: 'true' / 'false' - This will shorten the time remaining (when charging or discharging) to `~H:MM`.
Battery between 99% and 51% charged:<br/>
![battery_status_bg_yellow](/screenshots/battery_status_bg_yellow.png)
### Defaults
Battery between 50% and 16% charged:<br/>
![battery_status_bg_orange](/screenshots/battery_status_bg_orange.png)
#### Options
Battery between 15% and dead:<br/>
![battery_status_bg_red](/screenshots/battery_status_bg_red.png)
- `@batt_remain_short`: 'false'
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
- `#{battery_remain}` - will show remaining time of battery charge
- `#{battery_status_bg}` - will set the background color of the status bar based on the battery percentage
- `#{battery_status_fg}` - will set the foreground color of the status bar based on the battery percentage
- `#{battery_graph}` - will show battery percentage as a bar graph ▁▂▃▅▇
#### Icons/Colors
## Changing icons
By default, the following colors and icons are used. (The exact colors displayed depends on your terminal / X11 config.)
By default, these icons are displayed:
Please be aware that the 'level of charge' as noted below (e.g. `[80%-95%)`) uses interval notation. If you are unfamiliar with it, <a href="https://en.wikipedia.org/wiki/Bracket_(mathematics)#Intervals">check it out here</a>.
- charged: ":battery:" ("❇ " when not on OS X)
- charging: ":zap:"
- discharging: Moon icons depending on your battery level
- attached but not charging: ":warning:"
Also, a note about the `@batt_color_...` options: `@batt_color_..._primary` options are what will be displayed in the main `bg` or `fg` format strings you choose - e.g. if you use `#{battery_color_bg}`, the `@batt_color_..._primary` color you choose will be the background. Likewise, the corresponding `@batt_color_..._secondary` color will be the foreground.
You can change these defaults by adding the following to `.tmux.conf` (the
following lines are not in the code block so that emojis can be seen):
Level of Charge Colors:
- set -g @batt_charged_icon ":sunglasses:"
- set -g @batt_charging_icon ":+1:"
- set -g @batt_attached_icon ":neutral_face:"
- set -g @batt_full_charge_icon "🌕 "
- set -g @batt_high_charge_icon "🌖 "
- set -g @batt_medium_charge_icon "🌗 "
- set -g @batt_low_charge_icon "🌘 "
- primary tier 8 \[95%-100%] (`@batt_tier8_charge_color_primary`): '#00ff00'
- primary tier 7 \[80%-95%) (`@batt_tier7_charge_color_primary`): '#55ff00'
- primary tier 6 \[65%-80%) (`@batt_tier6_charge_color_primary`): '#aaff00'
- primary tier 5 \[50%-65%) (`@batt_tier5_charge_color_primary`): '#ffff00'
- primary tier 4 \[35%-50%) (`@batt_tier4_charge_color_primary`): '#ffc000'
- primary tier 3 \[20%-35%) (`@batt_tier3_charge_color_primary`): '#ff8000'
- primary tier 2 (5%-20%) (`@batt_tier2_charge_color_primary`): '#ff4000'
- primary tier 1 \[0%-5%] (`@batt_tier1_charge_color_primary`): '#ff0000'
- secondary tier 8 \[95%-100%] (`@batt_tier8_charge_color_secondary`): 'colour0'
- secondary tier 7 \[80%-95%) (`@batt_tier7_charge_color_secondary`): 'colour0'
- secondary tier 6 \[65%-80%) (`@batt_tier6_charge_color_secondary`): 'colour0'
- secondary tier 5 \[50%-65%) (`@batt_tier5_charge_color_secondary`): 'colour0'
- secondary tier 4 \[35%-50%) (`@batt_tier4_charge_color_secondary`): 'colour0'
- secondary tier 3 \[20%-35%) (`@batt_tier3_charge_color_secondary`): 'colour0'
- secondary tier 2 (5%-20%) (`@batt_tier2_charge_color_secondary`): 'colour0'
- secondary tier 1 \[0%-5%] (`@batt_tier1_charge_color_secondary`): 'colour0'
Don't forget to reload tmux environment (`$ tmux source-file ~/.tmux.conf`)
after you do this.
Status Colors:
- primary charged (`@batt_color_primary_charged`): 'colour33'
- primary charging (`@batt_color_primary_charging`): 'colour33'
- primary discharging (`@batt_color_primary_discharging`): 'colour14'
- primary attached (`@batt_color_primary_attached`): 'colour201'
- primary unknown (`@batt_color_primary_unknown`): 'colour7'
- secondary charged (`@batt_color_secondary_charged`): 'colour0'
- secondary charging (`@batt_color_secondary_charging`): 'colour0'
- secondary discharging (`@batt_color_secondary_discharging`): 'colour0'
- secondary attached (`@batt_color_secondary_attached`): 'colour0'
- secondary unknown (`@batt_color_secondary_unknown`): 'colour0'
Level of Charge Icons:
- tier 8 \[95%-100%] (`@batt_tier8_charge_icon`): '█'
- tier 7 \[80%-95%) (`@batt_tier7_charge_icon`): '▇'
- tier 6 \[65%-80%) (`@batt_tier6_charge_icon`): '▆'
- tier 5 \[50%-65%) (`@batt_tier5_charge_icon`): '▅'
- tier 4 \[35%-50%) (`@batt_tier4_charge_icon`): '▄'
- tier 3 \[20%-35%) (`@batt_tier3_charge_icon`): '▃'
- tier 2 (5%-20%) (`@batt_tier2_charge_icon`): '▂'
- tier 1 \[0%-5%] (`@batt_tier1_charge_icon`): '▁'
Status Icons:
- charged (`@batt_icon_charged`): '🔌'
- charged - OS X (`@batt_icon_charged`): '🔌'
- charging (`@batt_icon_charging`): '🔌'
- discharging (`@batt_icon_discharging`): '🔋'
- attached (`@batt_icon_attached`): '⚠️'
- unknown (`@batt_icon_unknown`): '?'
#### Changing the Defaults
All efforts have been made to make sane defaults, but if you wish to change any of them, add the option to `.tmux.conf`. For example:
```tmux
set -g @batt_icon_charge_tier8 '🌕'
set -g @batt_icon_charge_tier7 '🌖'
set -g @batt_icon_charge_tier6 '🌖'
set -g @batt_icon_charge_tier5 '🌗'
set -g @batt_icon_charge_tier4 '🌗'
set -g @batt_icon_charge_tier3 '🌘'
set -g @batt_icon_charge_tier2 '🌘'
set -g @batt_icon_charge_tier1 '🌑'
set -g @batt_icon_status_charged '🔋'
set -g @batt_icon_status_charging '⚡'
set -g @batt_icon_status_discharging '👎'
set -g @batt_color_status_primary_charged '#3daee9'
set -g @batt_color_status_primary_charging '#3daee9'
```
Don't forget to reload the tmux environment after you do this by either hitting `<prefix> + I` if tmux battery is installed via the tmux plugin manager, or by typing `tmux source-file ~/.tmux.conf` in the terminal if tmux battery is manually installed.
*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
## Examples
To shorten the output of `#{battery_remain}`, set the following variable:
These are all examples of the default plugin color and icon schemes paired with the default tmux color scheme using the following `status-right` and `status-right-length` settings in `.tmux.conf`
set -g @batt_remain_short true
```tmux
set -g status-right 'Colors: #{battery_color_bg}bg#[default] #{battery_color_fg}fg#[default] #{battery_color_charge_bg}charge_bg#[default] #{battery_color_charge_fg}charge_fg#[default] #{battery_color_status_bg}status_bg#[default] #{battery_color_status_fg}status_fg#[default] | Graph: #{battery_graph} | Icon: #{battery_icon} | Charge Icon: #{battery_icon_charge} | Status Icon: #{battery_icon_status} | Percent: #{battery_percentage} | Remain: #{battery_remain}'
set -g status-right-length '150'
```
This will shorten the time remaining (when charging or discharging) to `~H:MM`.
Battery charging at tier 8 \[95%-100%]:<br>
![battery-charging-tier8](./screenshots/battery_charging_tier8.png)
Battery charging at tier 7 \[80%-95%):<br>
![battery-charging-tier7](./screenshots/battery_charging_tier7.png)
Battery charging at tier 6 \[65%-80%):<br>
![battery-charging-tier6](./screenshots/battery_charging_tier6.png)
Battery charging at tier 5 \[50%-65%):<br>
![battery-charging-tier5](./screenshots/battery_charging_tier5.png)
Battery charging at tier 4 \[35%-50%):<br>
![battery-charging-tier4](./screenshots/battery_charging_tier4.png)
Battery charging at tier 3 \[20%-35%):<br>
![battery-charging-tier3](./screenshots/battery_charging_tier3.png)
Battery charging at tier 2 (5%-20%):<br>
![battery-charging-tier2](./screenshots/battery_charging_tier2.png)
Battery charging at tier 1 \[0%-5%]:<br>
![battery-charging-tier1](./screenshots/battery_charging_tier1.png)
Battery discharging at tier 8 \[95%-100%]:<br>
![battery-discharging-tier8](./screenshots/battery_discharging_tier8.png)
Battery discharging at tier 7 \[80%-95%):<br>
![battery-discharging-tier7](./screenshots/battery_discharging_tier7.png)
Battery discharging at tier 6 \[65%-80%):<br>
![battery-discharging-tier6](./screenshots/battery_discharging_tier6.png)
Battery discharging at tier 5 \[50%-65%):<br>
![battery-discharging-tier5](./screenshots/battery_discharging_tier5.png)
Battery discharging at tier 4 \[35%-50%):<br>
![battery-discharging-tier4](./screenshots/battery_discharging_tier4.png)
Battery discharging at tier 3 \[20%-35%):<br>
![battery-discharging-tier3](./screenshots/battery_discharging_tier3.png)
Battery discharging at tier 2 (5%-20%):<br>
![battery-discharging-tier2](./screenshots/battery_discharging_tier2.png)
Battery discharging at tier 1 \[0%-5%]:<br>
![battery-discharging-tier1](./screenshots/battery_discharging_tier1.png)
Battery in 'attached' status:<br>
![battery-status-attached](./screenshots/battery_status_attached.png)
Battery in an unknown status:<br>
![battery-status-unknown](./screenshots/battery_status_unknown.png)
### Tmux Plugins

View file

@ -5,20 +5,33 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/scripts/helpers.sh"
battery_interpolation=(
"\#{battery_color_bg}"
"\#{battery_color_fg}"
"\#{battery_color_charge_bg}"
"\#{battery_color_charge_fg}"
"\#{battery_color_status_bg}"
"\#{battery_color_status_fg}"
"\#{battery_graph}"
"\#{battery_icon}"
"\#{battery_icon_charge}"
"\#{battery_icon_status}"
"\#{battery_percentage}"
"\#{battery_remain}"
"\#{battery_icon}"
"\#{battery_status_bg}"
"\#{battery_status_fg}"
"\#{battery_graph}"
)
battery_commands=(
"#($CURRENT_DIR/scripts/battery_color.sh bg)"
"#($CURRENT_DIR/scripts/battery_color.sh fg)"
"#($CURRENT_DIR/scripts/battery_color_charge.sh bg)"
"#($CURRENT_DIR/scripts/battery_color_charge.sh fg)"
"#($CURRENT_DIR/scripts/battery_color_status.sh bg)"
"#($CURRENT_DIR/scripts/battery_color_status.sh fg)"
"#($CURRENT_DIR/scripts/battery_graph.sh)"
"#($CURRENT_DIR/scripts/battery_icon.sh)"
"#($CURRENT_DIR/scripts/battery_icon_charge.sh)"
"#($CURRENT_DIR/scripts/battery_icon_status.sh)"
"#($CURRENT_DIR/scripts/battery_percentage.sh)"
"#($CURRENT_DIR/scripts/battery_remain.sh)"
"#($CURRENT_DIR/scripts/battery_icon.sh)"
"#($CURRENT_DIR/scripts/battery_status_bg.sh)"
"#($CURRENT_DIR/scripts/battery_status_fg.sh)"
"#($CURRENT_DIR/scripts/battery_graph.sh)"
)
set_tmux_option() {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

23
scripts/battery_color.sh Executable file
View file

@ -0,0 +1,23 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
print_color() {
local plane="$1"
local status="$2"
if [ "$status" == "discharging" ]; then
$CURRENT_DIR/battery_color_charge.sh "$plane"
else
$CURRENT_DIR/battery_color_status.sh "$plane" "$status"
fi
}
main() {
local status="$(battery_status)"
local plane="$1"
print_color "$plane" "$status"
}
main $@

98
scripts/battery_color_charge.sh Executable file
View file

@ -0,0 +1,98 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
# script global variables
color_charge_primary_tier8=''
color_charge_primary_tier7=''
color_charge_primary_tier6=''
color_charge_primary_tier5=''
color_charge_primary_tier4=''
color_charge_primary_tier3=''
color_charge_primary_tier2=''
color_charge_primary_tier1=''
color_charge_secondary_tier8=''
color_charge_secondary_tier7=''
color_charge_secondary_tier6=''
color_charge_secondary_tier5=''
color_charge_secondary_tier4=''
color_charge_secondary_tier3=''
color_charge_secondary_tier2=''
color_charge_secondary_tier1=''
# script default variables
color_charge_primary_tier8_default='#00ff00'
color_charge_primary_tier7_default='#55ff00'
color_charge_primary_tier6_default='#aaff00'
color_charge_primary_tier5_default='#ffff00'
color_charge_primary_tier4_default='#ffc000'
color_charge_primary_tier3_default='#ff8000'
color_charge_primary_tier2_default='#ff4000'
color_charge_primary_tier1_default='#ff0000'
color_charge_secondary_tier8_default='colour0'
color_charge_secondary_tier7_default='colour0'
color_charge_secondary_tier6_default='colour0'
color_charge_secondary_tier5_default='colour0'
color_charge_secondary_tier4_default='colour0'
color_charge_secondary_tier3_default='colour0'
color_charge_secondary_tier2_default='colour0'
color_charge_secondary_tier1_default='colour0'
# colors are set as script global variables
get_color_charge_settings() {
color_charge_primary_tier8=$(get_tmux_option "@batt_color_charge_primary_tier8" "$color_charge_primary_tier8_default")
color_charge_primary_tier7=$(get_tmux_option "@batt_color_charge_primary_tier7" "$color_charge_primary_tier7_default")
color_charge_primary_tier6=$(get_tmux_option "@batt_color_charge_primary_tier6" "$color_charge_primary_tier6_default")
color_charge_primary_tier5=$(get_tmux_option "@batt_color_charge_primary_tier5" "$color_charge_primary_tier5_default")
color_charge_primary_tier4=$(get_tmux_option "@batt_color_charge_primary_tier4" "$color_charge_primary_tier4_default")
color_charge_primary_tier3=$(get_tmux_option "@batt_color_charge_primary_tier3" "$color_charge_primary_tier3_default")
color_charge_primary_tier2=$(get_tmux_option "@batt_color_charge_primary_tier2" "$color_charge_primary_tier2_default")
color_charge_primary_tier1=$(get_tmux_option "@batt_color_charge_primary_tier1" "$color_charge_primary_tier1_default")
color_charge_secondary_tier8=$(get_tmux_option "@batt_color_charge_secondary_tier8" "$color_charge_secondary_tier8_default")
color_charge_secondary_tier7=$(get_tmux_option "@batt_color_charge_secondary_tier7" "$color_charge_secondary_tier7_default")
color_charge_secondary_tier6=$(get_tmux_option "@batt_color_charge_secondary_tier6" "$color_charge_secondary_tier6_default")
color_charge_secondary_tier5=$(get_tmux_option "@batt_color_charge_secondary_tier5" "$color_charge_secondary_tier5_default")
color_charge_secondary_tier4=$(get_tmux_option "@batt_color_charge_secondary_tier4" "$color_charge_secondary_tier4_default")
color_charge_secondary_tier3=$(get_tmux_option "@batt_color_charge_secondary_tier3" "$color_charge_secondary_tier3_default")
color_charge_secondary_tier2=$(get_tmux_option "@batt_color_charge_secondary_tier2" "$color_charge_secondary_tier2_default")
color_charge_secondary_tier1=$(get_tmux_option "@batt_color_charge_secondary_tier1" "$color_charge_secondary_tier1_default")
}
print_color_charge() {
local primary_plane="$1"
local secondary_plane=""
if [ "$primary_plane" == "bg" ]; then
secondary_plane="fg"
else
secondary_plane="bg"
fi
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
if [ $percentage -ge 95 -o "$percentage" == "" ]; then
# if percentage is empty, assume it's a desktop
printf "#[$primary_plane=$color_charge_primary_tier8${color_charge_secondary_tier8:+",$secondary_plane=$color_charge_secondary_tier8"}]"
elif [ $percentage -ge 80 ]; then
printf "#[$primary_plane=$color_charge_primary_tier7${color_charge_secondary_tier7:+",$secondary_plane=$color_charge_secondary_tier7"}]"
elif [ $percentage -ge 65 ]; then
printf "#[$primary_plane=$color_charge_primary_tier6${color_charge_secondary_tier6:+",$secondary_plane=$color_charge_secondary_tier6"}]"
elif [ $percentage -ge 50 ]; then
printf "#[$primary_plane=$color_charge_primary_tier5${color_charge_secondary_tier5:+",$secondary_plane=$color_charge_secondary_tier5"}]"
elif [ $percentage -ge 35 ]; then
printf "#[$primary_plane=$color_charge_primary_tier4${color_charge_secondary_tier4:+",$secondary_plane=$color_charge_secondary_tier4"}]"
elif [ $percentage -ge 20 ]; then
printf "#[$primary_plane=$color_charge_primary_tier3${color_charge_secondary_tier3:+",$secondary_plane=$color_charge_secondary_tier3"}]"
elif [ $percentage -gt 5 ]; then
printf "#[$primary_plane=$color_charge_primary_tier2${color_charge_secondary_tier2:+",$secondary_plane=$color_charge_secondary_tier2"}]"
else
printf "#[$primary_plane=$color_charge_primary_tier1${color_charge_secondary_tier1:+",$secondary_plane=$color_charge_secondary_tier1"}]"
fi
}
main() {
local plane="$1"
get_color_charge_settings
print_color_charge "$plane"
}
main $@

74
scripts/battery_color_status.sh Executable file
View file

@ -0,0 +1,74 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
# script global variables
color_status_primary_charged=''
color_status_primary_charging=''
color_status_primary_discharging=''
color_status_primary_attached=''
color_status_primary_unknown=''
color_status_secondary_charged=''
color_status_secondary_charging=''
color_status_secondary_discharging=''
color_status_secondary_attached=''
color_status_secondary_unknown=''
# script default variables
color_status_primary_charged_default='colour33'
color_status_primary_charging_default='colour33'
color_status_primary_discharging_default='colour14'
color_status_primary_attached_default='colour201'
color_status_primary_unknown_default='colour7'
color_status_secondary_charged_default='colour0'
color_status_secondary_charging_default='colour0'
color_status_secondary_discharging_default='colour0'
color_status_secondary_attached_default='colour0'
color_status_secondary_unknown_default='colour0'
# colors are set as script global variables
get_color_status_settings() {
color_status_primary_charged=$(get_tmux_option "@batt_color_status_primary_charged" "$color_status_primary_charged_default")
color_status_primary_charging=$(get_tmux_option "@batt_color_status_primary_charging" "$color_status_primary_charging_default")
color_status_primary_discharging=$(get_tmux_option "@batt_color_status_primary_discharging" "$color_status_primary_discharging_default")
color_status_primary_attached=$(get_tmux_option "@batt_color_status_primary_attached" "$color_status_primary_attached_default")
color_status_primary_unknown=$(get_tmux_option "@batt_color_status_primary_unknown" "$color_status_primary_unknown_default")
color_status_secondary_charged=$(get_tmux_option "@batt_color_status_secondary_charged" "$color_status_secondary_charged_default")
color_status_secondary_charging=$(get_tmux_option "@batt_color_status_secondary_charging" "$color_status_secondary_charging_default")
color_status_secondary_discharging=$(get_tmux_option "@batt_color_status_secondary_discharging" "$color_status_secondary_discharging_default")
color_status_secondary_attached=$(get_tmux_option "@batt_color_status_secondary_attached" "$color_status_secondary_attached_default")
color_status_secondary_unknown=$(get_tmux_option "@batt_color_status_secondary_unknown" "$color_status_secondary_unknown_default")
}
print_color_status() {
local plane_primary="$1"
local plane_secondary=""
if [ "$plane_primary" == "bg" ]; then
plane_secondary="fg"
else
plane_secondary="bg"
fi
local status="$2"
if [[ $status =~ (charged) || $status =~ (full) ]]; then
printf "#[$plane_primary=$color_status_primary_charged${color_status_secondary_charged:+",$plane_secondary=$color_status_secondary_charged"}]"
elif [[ $status =~ (^charging) ]]; then
printf "#[$plane_primary=$color_status_primary_charging${color_status_secondary_charging:+",$plane_secondary=$color_status_secondary_charging"}]"
elif [[ $status =~ (^discharging) ]]; then
printf "#[$plane_primary=$color_status_primary_discharging${color_status_secondary_discharging:+",$plane_secondary=$color_status_secondary_discharging"}]"
elif [[ $status =~ (attached) ]]; then
printf "#[$plane_primary=$color_status_primary_attached${color_status_secondary_attached:+",$plane_secondary=$color_status_secondary_attached"}]"
else
printf "#[$plane_primary=$color_status_primary_unknown${color_status_secondary_unknown:+",$plane_secondary=$color_status_secondary_unknown"}]"
fi
}
main() {
local plane="$1"
local status=${2:-$(battery_status)}
get_color_status_settings
print_color_status "$plane" "$status"
}
main $@

View file

@ -5,17 +5,31 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
print_graph() {
if [ -z "$1" ]; then
echo ""
elif [ "$1" -lt "20" ]; then
echo "▁"
elif [ "$1" -lt "40" ]; then
echo "▂"
elif [ "$1" -lt "60" ]; then
echo "▃"
elif [ "$1" -lt "80" ]; then
echo "▅"
local percentage=$1
if [ $percentage -gt 5 ]; then
printf "▁"
else
printf " "
fi
if [ $percentage -ge 25 ]; then
printf "▂"
else
printf " "
fi
if [ $percentage -ge 50 ]; then
printf "▄"
else
printf " "
fi
if [ $percentage -ge 75 ]; then
printf "▆"
else
printf " "
fi
if [ $percentage -ge 95 ]; then
printf "█"
else
printf " "
echo "▇"
fi
}

View file

@ -4,72 +4,18 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
# script global variables
charged_icon=""
charging_icon=""
attached_icon=""
# discharging_icon=""
full_charge_icon=""
high_charge_icon=""
medium_charge_icon=""
low_charge_icon=""
charged_default="❇ "
charged_default_osx="🔋 "
charging_default="⚡️ "
attached_default="⚠️ "
full_charge_icon_default="🌕 "
high_charge_icon_default="🌖 "
medium_charge_icon_default="🌗 "
low_charge_icon_default="🌘 "
charged_default() {
if is_osx; then
echo "$charged_default_osx"
else
echo "$charged_default"
fi
}
# icons are set as script global variables
get_icon_settings() {
charged_icon=$(get_tmux_option "@batt_charged_icon" "$(charged_default)")
charging_icon=$(get_tmux_option "@batt_charging_icon" "$charging_default")
attached_icon=$(get_tmux_option "@batt_attached_icon" "$attached_default")
full_charge_icon=$(get_tmux_option "@batt_full_charge_icon" "$full_charge_icon_default")
high_charge_icon=$(get_tmux_option "@batt_high_charge_icon" "$high_charge_icon_default")
medium_charge_icon=$(get_tmux_option "@batt_medium_charge_icon" "$medium_charge_icon_default")
low_charge_icon=$(get_tmux_option "@batt_low_charge_icon" "$low_charge_icon_default")
}
print_icon() {
local status=$1
if [[ $status =~ (charged) || $status =~ (full) ]]; then
printf "$charged_icon"
elif [[ $status =~ (^charging) ]]; then
printf "$charging_icon"
elif [[ $status =~ (^discharging) ]]; then
# use code from the bg color
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
if [ $percentage -eq 100 ]; then
printf "$full_charge_icon"
elif [ $percentage -le 99 -a $percentage -ge 51 ];then
printf "$high_charge_icon"
elif [ $percentage -le 50 -a $percentage -ge 16 ];then
printf "$medium_charge_icon"
elif [ "$percentage" == "" ];then
printf "$full_charge_icon_default" # assume it's a desktop
else
printf "$low_charge_icon"
fi
elif [[ $status =~ (attached) ]]; then
printf "$attached_icon"
if [ "$status" == "discharging" ]; then
$CURRENT_DIR/battery_icon_charge.sh
else
$CURRENT_DIR/battery_icon_status.sh "$status"
fi
}
main() {
get_icon_settings
local status=$(battery_status)
print_icon "$status"
}
main

66
scripts/battery_icon_charge.sh Executable file
View file

@ -0,0 +1,66 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
# script global variables
icon_charge_tier8=''
icon_charge_tier7=''
icon_charge_tier6=''
icon_charge_tier5=''
icon_charge_tier4=''
icon_charge_tier3=''
icon_charge_tier2=''
icon_charge_tier1=''
# script default variables
icon_charge_tier8_default='█'
icon_charge_tier7_default='▇'
icon_charge_tier6_default='▆'
icon_charge_tier5_default='▅'
icon_charge_tier4_default='▄'
icon_charge_tier3_default='▃'
icon_charge_tier2_default='▂'
icon_charge_tier1_default='▁'
# icons are set as script global variables
get_icon_charge_settings() {
icon_charge_tier8=$(get_tmux_option "@batt_icon_charge_tier8" "$icon_charge_tier8_default")
icon_charge_tier7=$(get_tmux_option "@batt_icon_charge_tier7" "$icon_charge_tier7_default")
icon_charge_tier6=$(get_tmux_option "@batt_icon_charge_tier6" "$icon_charge_tier6_default")
icon_charge_tier5=$(get_tmux_option "@batt_icon_charge_tier5" "$icon_charge_tier5_default")
icon_charge_tier4=$(get_tmux_option "@batt_icon_charge_tier4" "$icon_charge_tier4_default")
icon_charge_tier3=$(get_tmux_option "@batt_icon_charge_tier3" "$icon_charge_tier3_default")
icon_charge_tier2=$(get_tmux_option "@batt_icon_charge_tier2" "$icon_charge_tier2_default")
icon_charge_tier1=$(get_tmux_option "@batt_icon_charge_tier1" "$icon_charge_tier1_default")
}
print_icon_charge() {
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
if [ $percentage -ge 95 -o "$percentage" == "" ]; then
# if percentage is empty, assume it's a desktop
printf "$icon_charge_tier8"
elif [ $percentage -ge 80 ]; then
printf "$icon_charge_tier7"
elif [ $percentage -ge 65 ]; then
printf "$icon_charge_tier6"
elif [ $percentage -ge 50 ]; then
printf "$icon_charge_tier5"
elif [ $percentage -ge 35 ]; then
printf "$icon_charge_tier4"
elif [ $percentage -ge 20 ]; then
printf "$icon_charge_tier3"
elif [ $percentage -gt 5 ]; then
printf "$icon_charge_tier2"
else
printf "$icon_charge_tier1"
fi
}
main() {
get_icon_charge_settings
print_icon_charge
}
main

61
scripts/battery_icon_status.sh Executable file
View file

@ -0,0 +1,61 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
# script global variables
icon_status_charged=''
icon_status_charging=''
icon_status_discharging=''
icon_status_attached=''
icon_status_unknown=''
# script default variables
icon_status_charged_default='🔌'
icon_status_charged_default_osx='🔌'
icon_status_charging_default='🔌'
icon_status_discharging_default='🔋'
icon_status_attached_default='⚠️'
icon_status_unknown_default='?'
# determine which charged_default variable to use
get_icon_status_charged_default() {
if is_osx; then
printf "$icon_status_charged_default_osx"
else
printf "$icon_status_charged_default"
fi
}
# icons are set as script global variables
get_icon_status_settings() {
icon_status_charged=$(get_tmux_option "@batt_icon_status_charged" "$(get_icon_status_charged_default)")
icon_status_charging=$(get_tmux_option "@batt_icon_status_charging" "$icon_status_charging_default")
icon_status_discharging=$(get_tmux_option "@batt_icon_status_discharging" "$icon_status_discharging_default")
icon_status_attached=$(get_tmux_option "@batt_icon_status_attached" "$icon_status_attached_default")
icon_status_unknown=$(get_tmux_option "@batt_icon_status_unknown" "$icon_status_unknown_default")
}
print_icon_status() {
local status=$1
if [[ $status =~ (charged) || $status =~ (full) ]]; then
printf "$icon_status_charged"
elif [[ $status =~ (^charging) ]]; then
printf "$icon_status_charging"
elif [[ $status =~ (^discharging) ]]; then
printf "$icon_status_discharging"
elif [[ $status =~ (attached) ]]; then
printf "$icon_status_attached"
else
printf "$icon_status_unknown"
fi
}
main() {
get_icon_status_settings
local status=${1:-$(battery_status)}
print_icon_status "$status"
}
main