aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.config/i3blocks/config21
-rwxr-xr-x.config/i3blocks/scripts/batterybar136
2 files changed, 149 insertions, 8 deletions
diff --git a/.config/i3blocks/config b/.config/i3blocks/config
index 884d9e9..9d80cc0 100644
--- a/.config/i3blocks/config
+++ b/.config/i3blocks/config
@@ -39,7 +39,7 @@ color=#006DA3
#
# The type defaults to "mem" if the instance is not specified.
[memory]
-label=MEM
+label=🐏
separator=false
interval=30
@@ -55,9 +55,10 @@ interval=30
# The script may be called with a optional argument to set the alert
# (defaults to 10 for 10%).
[disk]
-label=HOME
+label=
#instance=/mnt/data
interval=30
+separator=false
[disk-io]
label=
@@ -95,6 +96,12 @@ interval=10
#min_width=CPU: 100.00%
separator=false
+[load_average]
+interval=10
+separator=false
+label=AVG
+
+
#
# Temperature
#
@@ -106,21 +113,19 @@ label=TEMP
interval=10
command=/usr/lib/i3blocks/temperature --chip coretemp-isa-0000
-
-#[load_average]
-#interval=10
-
# Battery indicator
#
# The battery instance defaults to 0.
[battery]
+command=~/.config/i3blocks/scripts/batterybar
#label=BAT
-label= BAT
+markup=pango
+#label= BAT
#🔋
#⚡
#instance=1
interval=30
-separator=false
+#separator=false
[brightness]
command=~/.config/i3blocks/scripts/brightness.py
diff --git a/.config/i3blocks/scripts/batterybar b/.config/i3blocks/scripts/batterybar
new file mode 100755
index 0000000..7111af8
--- /dev/null
+++ b/.config/i3blocks/scripts/batterybar
@@ -0,0 +1,136 @@
+#!/usr/bin/env bash
+# batterybar; displays battery percentage as a bar on i3blocks
+#
+# Copyright 2015 Keftaa <adnan.37h@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+#
+readarray -t output <<< $(acpi battery)
+battery_count=${#output[@]}
+
+for line in "${output[@]}";
+do
+ percentages+=($(echo "$line" | grep -o -m1 '[0-9]\{1,3\}%' | tr -d '%'))
+ statuses+=($(echo "$line" | egrep -o -m1 'Discharging|Charging|AC|Full|Unknown'))
+ remaining=$(echo "$line" | egrep -o -m1 '[0-9][0-9]:[0-9][0-9]')
+ if [[ -n $remaining ]]; then
+ remainings+=(" ($remaining)")
+ else
+ remainings+=("")
+ fi
+done
+
+squares="■"
+
+#There are 8 colors that reflect the current battery percentage when
+#discharging
+dis_colors=("#FF0027" "#FF3B05" "#FFB923" "#FFD000" "#E4FF00" "#ADFF00"
+ "#6DFF00" "#10BA00")
+charging_color="#00AFE3"
+full_color="#FFFFFF"
+ac_color="#535353"
+
+
+while getopts 1:2:3:4:5:6:7:8:c:f:a:h opt; do
+ case "$opt" in
+ 1) dis_colors[0]="$OPTARG";;
+ 2) dis_colors[1]="$OPTARG";;
+ 3) dis_colors[2]="$OPTARG";;
+ 4) dis_colors[3]="$OPTARG";;
+ 5) dis_colors[4]="$OPTARG";;
+ 6) dis_colors[5]="$OPTARG";;
+ 7) dis_colors[6]="$OPTARG";;
+ 8) dis_colors[7]="$OPTARG";;
+ c) charging_color="$OPTARG";;
+ f) full_color="$OPTARG";;
+ a) ac_color="$OPTARG";;
+ h) printf "Usage: batterybar [OPTION] color
+ When discharging, there are 8 [1-8] levels colors.
+ You can specify custom colors, for example:
+
+ batterybar -1 red -2 \"#F6F6F6\" -8 green
+
+ You can also specify the colors for the charging, AC and
+ charged states:
+
+ batterybar -c green -f white -a \"#EEEEEE\"\n";
+ exit 0;
+ esac
+done
+
+end=$(($battery_count - 1))
+for i in $(seq 1 $end);
+do
+ if (( percentages[$i] > 0 && percentages[$i] < 10 )); then
+ squares=""
+ elif (( percentages[$i] >= 10 && percentages[$i] < 35 )); then
+ squares=""
+ elif (( percentages[$i] >= 35 && percentages[$i] < 65 )); then
+ squares=""
+ elif (( percentages[$i] >= 65 && percentages[$i] < 80 )); then
+ squares=""
+ elif (( percentages[$i] >=80 )); then
+ squares=""
+ fi
+
+ if [[ "${statuses[$i]}" = "Unknown" ]]; then
+ squares="<sup>?</sup>$squares"
+ fi
+
+ case "${statuses[$i]}" in
+ "Charging")
+ color="$charging_color"
+ ;;
+ "Full")
+ color="$full_color"
+ ;;
+ "AC")
+ color="$ac_color"
+ ;;
+ "Discharging"|"Unknown")
+ if (( percentages[$i] >= 0 && percentages[$i] < 10 )); then
+ color="${dis_colors[0]}"
+ elif (( percentages[$i] >= 10 && percentages[$i] < 20 )); then
+ color="${dis_colors[1]}"
+ elif (( percentages[$i] >= 20 && percentages[$i] < 30 )); then
+ color="${dis_colors[2]}"
+ elif (( percentages[$i] >= 30 && percentages[$i] < 40 )); then
+ color="${dis_colors[3]}"
+ elif (( percentages[$i] >= 40 && percentages[$i] < 60 )); then
+ color="${dis_colors[4]}"
+ elif (( percentages[$i] >= 60 && percentages[$i] < 70 )); then
+ color="${dis_colors[5]}"
+ elif (( percentages[$i] >= 70 && percentages[$i] < 80 )); then
+ color="${dis_colors[6]}"
+ elif (( percentages[$i] >= 80 )); then
+ color="${dis_colors[7]}"
+ fi
+ ;;
+ esac
+
+ # Print Battery number if there is more than one
+ if (( $end > 1 )) ; then
+ message="$message $(($i + 1)):"
+ fi
+
+ if [[ "$BLOCK_BUTTON" -eq 1 ]]; then
+ message="$message ${statuses[$i]} <span foreground=\"$color\">${percentages[$i]}%${remainings[i]}</span>"
+ fi
+ message="$message <span foreground=\"$color\">$squares</span>"
+done
+
+echo $message