add vertical box bar as default visual representaion for percentages

This commit is contained in:
koksnuss 2018-05-27 01:57:10 +02:00
parent 33dd3a4168
commit 8a2b50249b
8 changed files with 182 additions and 77 deletions

View File

@ -9,9 +9,9 @@ This is a simple collection of i3blocks-modules accompagnied by a config file wi
- module *datetime*: A left click will toggle long and short displays. The short version is displayed in the format `HH:MM`. The long version also shows the day of the week, weeknumber, date and seconds. - module *datetime*: A left click will toggle long and short displays. The short version is displayed in the format `HH:MM`. The long version also shows the day of the week, weeknumber, date and seconds.
- module *audio*: `instance=mic` will show the microphone level instead. With a left mouse click the device is muted/unmuted. - module *audio*: `instance=mic` will show the microphone level instead. With a left mouse click the device is muted/unmuted.
- module *ram*: by default free ram and swap are shown in the format `a+b G` where `a` is ram and `b` is swap. If you want to show ram and swap seperatly, use `instance=ram` or `instance=swap`. If you left click on the block, `top` will be openend. - module *ram*: by default free ram and swap are shown in the format `a+b G` where `a` is ram and `b` is swap. If you want to show ram and swap seperatly, use `instance=ram` or `instance=swap`. If you left click on the block, `top` will be openend.
- *cpu*: by default total idle cpu time of all cores together is displayed. If you left click on the block, `top` will be openend. - *cpu*: by default total idle cpu time of all cores together is displayed using a vertical block symbol. Use `instance=long` to show the percentage instead. If you left click on the block, `top` will be openend.
- module *battery*: By default the total energy left of all batteries is shown. Use `instance=x` to show the status of `BATx` in case you have more than one battery in `/sys/class/powersupply`. - module *battery*: By default the total energy left of all batteries is shown using a vertical block symbol. Use `instance=x` to show the status of `BATx` in case you have more than one battery in `/sys/class/powersupply`. On Left click, the long percentage is shown.
- module *backlight*: By default the brightness level is shown in the default font color (depending on your i3 config). Use `instance="color"` to print the brightness level colored which is nice when using a device in battery mode. - module *backlight*: By default the brightness level is shown in the default font color (depending on your i3 config). Use `instance=long` to show the brightness percentage. Use `instance="color"` to print the brightness level colored which is nice when using a device in battery mode. On left click the brightness in percent will be shown.
# Requirements # Requirements
Install [i3 window manager](https://i3wm.org) alongside with [i3blocks](https://github.com/vivien/i3blocks) and `git`. The following shows the requirements for each module: Install [i3 window manager](https://i3wm.org) alongside with [i3blocks](https://github.com/vivien/i3blocks) and `git`. The following shows the requirements for each module:

5
config
View File

@ -9,6 +9,7 @@ interval=5
label=☼ label=☼
# label=☀,☼,✱,✲,✳,✴,✵,✺ # label=☀,☼,✱,✲,✳,✴,✵,✺
instance=color instance=color
# instance=color,long
# [iface] # [iface]
# label=iface # label=iface
@ -21,12 +22,14 @@ label=⛁
# with instance=ram or instance=swap # with instance=ram or instance=swap
[ram] [ram]
label=⚟ label=⚟
# instance=long
# instance=ram # instance=ram
# [ram] # [ram]
# instance=swap # instance=swap
[cpu] [cpu]
label=☷ label=☷
# instance=long
[ip] [ip]
# label=ip # label=ip
@ -54,7 +57,7 @@ label=⎋
[audio] [audio]
label=◍ label=◍
# label=♩,♪,♫,♬ # label=♩,♪,♫,♬
separator_block_width=0 # separator_block_width=0
[audio] [audio]
label=◎ label=◎
# label=⋓ℹ⋒ⅈ # label=⋓ℹ⋒ⅈ

View File

@ -1,30 +1,55 @@
#!/bin/bash #!/bin/bash
[[ $BLOCK_INSTANCE == "mic" ]] && DEV="Capture" || DEV="Master" [[ "$BLOCK_INSTANCE" == "mic" ]] && DEV="Capture" || DEV="Master"
[[ $BLOCK_BUTTON == 1 ]] && amixer set $DEV toggle &> /dev/null [[ "$BLOCK_BUTTON" == 1 ]] && LONG=true
amixer get $DEV | gawk '
[[ "$BLOCK_BUTTON" == 2 ]] && amixer set $DEV toggle &> /dev/null
amixer get $DEV | gawk -v LONG="$LONG" '
match($0, /\[([0-9]+)\%\] \[(on|off)\]/, matches) { match($0, /\[([0-9]+)\%\] \[(on|off)\]/, matches) {
audio=matches[1] load=matches[1]
} }
END { END {
if (matches[2] == "off") { if (matches[2] == "off") {
print(" off \n")
print("off\n") print("off\n")
exit 33 print("X\n")
print("#CCCCCC")
} }
printf("%d% \n", audio) if (LONG == "true") {
printf("%d%\n", audio) printf("%d% \n", load)
if (audio < 75) { printf("%d%\n", load)
} else {
if (load < 100 / 9) {
printf("▁\n▁\n")
} else if (load < 100 / 9 * 2 ) {
printf("▁\n▁\n")
} else if (load < 100 / 9 * 3 ) {
printf("▂\n▂\n")
} else if (load < 100 / 9 * 4 ) {
printf("▃\n▃\n")
} else if (load < 100 / 9 * 5 ) {
printf("▄\n▄\n")
} else if (load < 100 / 9 * 6 ) {
printf("▅\n▅\n")
} else if (load < 100 / 9 * 7 ) {
printf("▆\n▆\n")
} else if (load < 100 / 9 * 8 ) {
printf("▇\n▇\n")
} else {
printf("█\n█\n")
}
}
if (load < 75) {
print("#04B431\n") print("#04B431\n")
} else if (audio < 80) { } else if (load < 80) {
print("#A8FF00\n") print("#A8FF00\n")
} else if (audio < 85) { } else if (load < 85) {
print("#FFF600\n") print("#FFF600\n")
} else if (audio < 90) { } else if (load < 90) {
print("#FFAE00\n") print("#FFAE00\n")
} else if (audio < 95) { } else if (load < 95) {
print("#FF0000\n") print("#FF0000\n")
} else { } else {
exit 33 exit 33

View File

@ -2,7 +2,8 @@
DIR="/sys/class/backlight" DIR="/sys/class/backlight"
[[ "${BLOCK_INSTANCE}" == "color" ]] && MODE="color" || MODE="bw" [[ "$BLOCK_INSTANCE" =~ "color" ]] && MODE="color" || MODE="bw"
[[ "$BLOCK_INSTANCE" =~ "long" || "$BLOCK_BUTTON" == 1 ]] && LONG=true
if [[ -d "$DIR/acpi_video0" ]]; then if [[ -d "$DIR/acpi_video0" ]]; then
DIR="$DIR/acpi_video0" DIR="$DIR/acpi_video0"
@ -14,26 +15,45 @@ else
exit 33 exit 33
fi fi
cat "$DIR/brightness" "$DIR/max_brightness" | gawk -v MODE="$MODE" ' cat "$DIR/brightness" "$DIR/max_brightness" | gawk -v MODE="$MODE" -v LONG="$LONG" '
NR==1 { current_brightness = $1 } NR==1 { cbr = $1 }
NR==2 { max_brightness = $1 } NR==2 { mbr = $1 }
END { END {
relative_brightness = ( current_brightness / max_brightness ) * 100 load = ( cbr / mbr ) * 100
printf("%d%\n", relative_brightness) if (LONG == "true") {
printf("%d\n", relative_brightness) printf("%d%\n", load)
if (MODE == "color") { } else {
if (relative_brightness < 50) { if (load < 100 / 9) {
print("#04B431\n") printf("▁\n▁\n")
} else if (relative_brightness < 60) { } else if (load < 100 / 9 * 2 ) {
print("#A8FF00\n") printf("▁\n▁\n")
} else if (relative_brightness < 70) { } else if (load < 100 / 9 * 3 ) {
print("#FFF600\n") printf("▂\n▂\n")
} else if (relative_brightness < 80) { } else if (load < 100 / 9 * 4 ) {
print("#FFAE00\n") printf("▃\n▃\n")
} else if (relative_brightness < 90) { } else if (load < 100 / 9 * 5 ) {
print("#FF0000\n") printf("▄\n▄\n")
} else if (load < 100 / 9 * 6 ) {
printf("▅\n▅\n")
} else if (load < 100 / 9 * 7 ) {
printf("▆\n▆\n")
} else if (load < 100 / 9 * 8 ) {
printf("▇\n▇\n")
} else { } else {
exit 33 printf("█\n█\n")
}
}
if (MODE == "color") {
if (load < 60) {
print("#04B431\n")
} else if (load < 50) {
print("#A8FF00\n")
} else if (load < 80) {
print("#FFF600\n")
} else if (load < 90) {
print("#FFAE00\n")
} else {
print("#FF0000\n")
} }
} else { } else {
printf("\n") printf("\n")

View File

@ -2,7 +2,7 @@
DIR="/sys/class/power_supply" DIR="/sys/class/power_supply"
[[ "$BLOCK_BUTTON" == "1" ]] && LONG=true || LONG=false [[ "$BLOCK_BUTTON" == "1" ]] && LONG=true
if [[ "$BLOCK_INSTANCE" == "" ]]; then if [[ "$BLOCK_INSTANCE" == "" ]]; then
for BAT in $DIR/BAT*/; do for BAT in $DIR/BAT*/; do
@ -41,8 +41,9 @@ cat $BATS | gawk -F '=' -v LONG="$LONG" '
} }
END { END {
charge = enow / efull * 100 charge = enow / efull * 100
if (LONG == "true") {
if (LONG == "false") { printf("%s%d%\n", status, charge)
} else {
if (charge < 100 / 9) { if (charge < 100 / 9) {
printf("\n") printf("\n")
} else if (charge < 100 / 9 * 2 ) { } else if (charge < 100 / 9 * 2 ) {
@ -62,8 +63,6 @@ cat $BATS | gawk -F '=' -v LONG="$LONG" '
} else { } else {
printf("%s█\n", status) printf("%s█\n", status)
} }
} else {
printf("%s%d%\n", status, charge)
} }
printf("%s%d\n", status, charge) printf("%s%d\n", status, charge)
if (charge > 25) { if (charge > 25) {

View File

@ -1,22 +1,46 @@
#!/bin/bash #!/bin/bash
[[ "$BLOCK_INSTANCE" =~ "long" ]] && LONG=true
[[ "$BLOCK_BUTTON" == 1 ]] && i3-sensible-terminal -e htop [[ "$BLOCK_BUTTON" == 1 ]] && i3-sensible-terminal -e htop
top -bn1 | gawk '
top -bn1 | gawk -v LONG="$LONG" '
/^\%CPU/ { /^\%CPU/ {
cpu = 100 - $8 load = 100 - $8
} }
END { END {
printf("%d%\n", cpu) if (LONG == "true") {
printf("%d\n", cpu) printf("%d%\n%d%\n", load, load)
if (cpu < 50) { } else {
if (load < 100 / 9) {
printf("▁\n▁\n")
} else if (load < 100 / 9 * 2 ) {
printf("▁\n▁\n")
} else if (load < 100 / 9 * 3 ) {
printf("▂\n▂\n")
} else if (load < 100 / 9 * 4 ) {
printf("▃\n▃\n")
} else if (load < 100 / 9 * 5 ) {
printf("▄\n▄\n")
} else if (load < 100 / 9 * 6 ) {
printf("▅\n▅\n")
} else if (load < 100 / 9 * 7 ) {
printf("▆\n▆\n")
} else if (load < 100 / 9 * 8 ) {
printf("▇\n▇\n")
} else {
printf("█\n█\n")
}
}
if (load < 50) {
print("#04B431\n") print("#04B431\n")
} else if (cpu < 60) { } else if (load < 60) {
print("#A8FF00\n") print("#A8FF00\n")
} else if (cpu < 70) { } else if (load < 70) {
print("#FFF600\n") print("#FFF600\n")
} else if (cpu < 80) { } else if (load < 80) {
print("#FFAE00\n") print("#FFAE00\n")
} else if (cpu < 90) { } else if (load < 90) {
print("#FF0000\n") print("#FF0000\n")
} else { } else {
exit 33 exit 33

View File

@ -2,17 +2,25 @@
[[ "$BLOCK_BUTTON" == 1 ]] && i3-sensible-terminal -e htop [[ "$BLOCK_BUTTON" == 1 ]] && i3-sensible-terminal -e htop
case "${BLOCK_INSTANCE}" in [[ "$BLOCK_INSTANCE" =~ "long" ]] && LONG=true
swap) TYPE="swap";;
ram) TYPE="ram";;
*) TYPE="";;
esac
gawk -v TYPE="$TYPE" ' if [[ "$BLOCK_INSTANCE" =~ "ram" ]]; then
TYPE='swap'
elif [[ "$BLOCK_INSTANCE" =~ "swap" ]]; then
TYPE='swap'
fi
gawk -v TYPE="$TYPE" -v LONG="$LONG" '
/^MemTotal/ {
rtg = $2 / 1024^2
}
/^MemAvailable/ { /^MemAvailable/ {
rfg = $2 / 1024^2 rfg = $2 / 1024^2
rfm = $2 / 1024 rfm = $2 / 1024
} }
/^SwapTotal/ {
stg = $2 / 1024^2
}
/^SwapFree/ { /^SwapFree/ {
sfg = $2 / 1024^2 sfg = $2 / 1024^2
sfm = $2 / 1024 sfm = $2 / 1024
@ -21,31 +29,56 @@ gawk -v TYPE="$TYPE" '
if (TYPE == "") { if (TYPE == "") {
mfg = rfg + sfg mfg = rfg + sfg
mfm = rfm + sfm mfm = rfm + sfm
if (mfg > 2) { mtg = rtg + stg
printf("%d+%d G\n", rfg, sfg)
printf("%d+%dG\n", rfg, sfg)
} else {
printf("%d+%d M\n", rfm, sfm)
printf("%d+%dM\n", rfm, sfm)
}
} else if (TYPE == "ram") { } else if (TYPE == "ram") {
if (rfg > 2) { mfg = rfg
printf("%d G\n", rfg) mfm = rfm
printf("%dG\n", rfg) mtg = rtg
mfg = rfg
} else {
printf("%d M\n", rfm)
printf("%dM\n", rfm)
}
} else if (TYPE == "swap") { } else if (TYPE == "swap") {
if (sfg > 2) { mfg = sfg
printf("%d G\n", sfg) mfm = sfm
printf("%dG\n", sfg) rtg = stg
mfg = sfg }
if (LONG == "true") {
if (TYPE == "") {
if (mfg > 2) {
printf("%d+%d G\n", rfg, sfg)
printf("%d+%dG\n", rfg, sfg)
} else {
printf("%d+%d M\n", rfm, sfm)
printf("%d+%dM\n", rfm, sfm)
}
} else { } else {
printf("%d M\n", sfm) if (mfg > 2) {
printf("%dM\n", sfm) printf("%d G\n", mfg)
printf("%dG\n", mfg)
mfg = rfg
} else {
printf("%d M\n", mfm)
printf("%dM\n", mfm)
}
} }
} else {
load = mfg / mtg
if (load < 100 / 9) {
printf("▁\n▁\n")
} else if (load < 100 / 9 * 2 ) {
printf("▁\n▁\n")
} else if (load < 100 / 9 * 3 ) {
printf("▂\n▂\n")
} else if (load < 100 / 9 * 4 ) {
printf("▃\n▃\n")
} else if (load < 100 / 9 * 5 ) {
printf("▄\n▄\n")
} else if (load < 100 / 9 * 6 ) {
printf("▅\n▅\n")
} else if (load < 100 / 9 * 7 ) {
printf("▆\n▆\n")
} else if (load < 100 / 9 * 8 ) {
printf("▇\n▇\n")
} else {
printf("█\n█\n")
}
} }
if (mfg > 5) { if (mfg > 5) {
print("#04B431\n") print("#04B431\n")

View File

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
df | gawk ' df | gawk '
/\/$/ { /\/$/ {
free_storage=$4/1024^2 free_storage=$4/1024^2