refractor: move code to abstract.sh enable unique and central color palette and progress bar

This commit is contained in:
koksnuss 2018-08-10 15:13:31 +02:00
parent 11f963804e
commit 451dd44eac
19 changed files with 325 additions and 403 deletions

View File

@ -53,21 +53,35 @@ One-Liner: Open up a terminal and paste: `bash <(curl -s https://will.kein.hk/gi
- [x] battery
- [x] backlight
- [ ] wifi/ethernet/bluetooth
- [ ] external storage
- [ ] mount
- [ ] ethernet bandwith
## Refractor
- [ ] centralize color palette and progress bar
- [ ] centralize long/short view: rewrite config + i3reload? how to make it permanent?
- [ ] centralize click interactions
## Click interactions
- [x] general: left: toggle long preview
- [x] audio/mic: middle: open pavucontrol, right: toggle mute
- [x] ram/cpu/temp: middle: open htop
- [x] storage: middle: open ranger
- [x] ip: middle: open firefox
- [ ] external storage: mount it somewhere
### Long/Short preview: Middle click
- [ ] Toggle long (numbers and units) and short (representative bar) preview
### Open another program: Left click
- [c] audio/mic: open pavucontrol
- [c] ram/cpu/temp: open htop
- [c] storage: open ranger
- [c] ip: middle: open firefox
- [ ] mount: mount it somewhere (with pmount?) and open ranger
### Other behaviour
- [c] audio/mic: toggle mute
- [ ] onn/off behaviour: backlight, ethernet, audio, mic
## Signals
- [x] audio, mic
- [ ] backlight
- [ ] mount
## Other
## Other features
- [x] nice icons as labels
- [x] showing percentage values as a vertical bar

4
config
View File

@ -2,14 +2,14 @@
markup=none
separator_block_width=15
separator=false
command=$HOME/.config/i3blocks/modules/$BLOCK_NAME
command=$HOME/.config/i3blocks/modules/abstract.sh $BLOCK_NAME
interval=5
[backlight]
label=☼
# label=☀,☼,✱,✲,✳,✴,✵,✺
signal=3
instance=color,long
instance=long
# instance=color,bw,long
# [iface]

10
modules/abstract.sh Executable file
View File

@ -0,0 +1,10 @@
[[ "$BLOCK_INSTANCE" =~ "color" ]] && COLORS=True
[[ "$BLOCK_INSTANCE" =~ "long" || "$BLOCK_BUTTON" == 1 ]] && LONG=True
BAR=("▁" "▂" "▃" "▄" "▅" "▆" "▇" "█")
COLOR=("#64bc01" "#77a601" "#8a9101" "#9d7b00" "#b06701" "#c45100" "#d63c00" "#e92700")
BW=("#565656" "#6d6d6d" "#848485" "#9c9c9c" "#b1b1b1" "#c7c7c7" "#dcdcdc" "#f5f5f6")
source $HOME/.config/i3blocks/modules/${1}.sh

View File

@ -1,60 +0,0 @@
#!/bin/bash
[[ "$BLOCK_INSTANCE" == "mic" ]] && DEV="Capture" || DEV="Master"
[[ "$BLOCK_BUTTON" == 1 ]] && LONG=true
[[ "$BLOCK_BUTTON" == 2 ]] && pavucontrol &
[[ "$BLOCK_BUTTON" == 3 ]] && amixer set $DEV toggle &> /dev/null
amixer get $DEV | gawk -v LONG="$LONG" '
match($0, /\[([0-9]+)\%\] \[(on|off)\]/, matches) {
load=matches[1]
}
END {
if (matches[2] == "off") {
print("off\n")
print("X\n")
print("#CCCCCC")
} else {
if (LONG == "true") {
printf("%d% \n", load)
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")
} else if (load < 80) {
print("#A8FF00\n")
} else if (load < 85) {
print("#FFF600\n")
} else if (load < 90) {
print("#FFAE00\n")
} else if (load < 95) {
print("#FF0000\n")
} else {
exit 33
}
}
}
'

46
modules/audio.sh Executable file
View File

@ -0,0 +1,46 @@
[[ "$BLOCK_INSTANCE" =~ "mic" ]] && DEV="Capture" || DEV="Master"
[[ "$BLOCK_BUTTON" == 2 ]] && pavucontrol &
[[ "$BLOCK_BUTTON" == 3 ]] && amixer set $DEV toggle &> /dev/null
amixer get $DEV | gawk -v BAR="${BAR[*]}" -v BW="${BW[*]}" -v COLORS="$COLORS" -v COLOR="${COLOR[*]}" -v LONG="$LONG" '
BEGIN {
split(BAR, bar, / /)
split(COLOR, color, / /)
split(BW, bw, / /)
interval = 100 / length(bar)
}
match($0, /\[([0-9]+)\%\] \[(on|off)\]/, matches) {
load = matches[1]
}
END {
if (matches[2] == "off") {
print("off\n")
print("X\n")
print("#CCCCCC")
} else {
if (LONG) {
printf("%d%\n%d\n", load, load)
} else {
for (i in bar) {
if (load <= i * interval) {
printf("%s\n%s\n", bar[i], bar[i])
break
}
}
}
for (i in bw) {
if (load <= i * interval) {
if (COLORS) {
printf("%s\n", color[i])
} else {
printf("%s\n", bw[i])
}
break
}
}
}
}
'

View File

@ -1,9 +1,4 @@
#!/bin/bash
DIR="/sys/class/backlight"
[[ "$BLOCK_INSTANCE" =~ "color" ]] && COLORS=True
[[ "$BLOCK_INSTANCE" =~ "long" || "$BLOCK_BUTTON" == 1 ]] && LONG=True
if [[ -d "$DIR/acpi_video0" ]]; then
DIR="$DIR/acpi_video0"
elif [[ -d "$DIR/intel_backlight" ]]; then
@ -13,11 +8,7 @@ else
exit 33
fi
BAR=("▁" "▂" "▃" "▄" "▅" "▆" "▇" "█")
COLOR=("#64bc01" "#77a601" "#8a9101" "#9d7b00" "#b06701" "#c45100" "#d63c00" "#e92700")
BW=("#565656" "#6d6d6d" "#848485" "#9c9c9c" "#b1b1b1" "#c7c7c7" "#dcdcdc" "#f5f5f6")
cat "$DIR/brightness" "$DIR/max_brightness" | gawk -v BAR="${BAR[*]}" -v COLOR="${COLOR[*]}" -v BW="${BW[*]}" -v COLORS="$COLORS" -v LONG="$LONG" '
cat "$DIR/brightness" "$DIR/max_brightness" | gawk -v BAR="${BAR[*]}" -v BW="${BW[*]}" -v COLORS="$COLORS" -v COLOR="${COLOR[*]}" -v LONG="$LONG" '
BEGIN {
split(BAR, bar, / /)
@ -30,19 +21,19 @@ cat "$DIR/brightness" "$DIR/max_brightness" | gawk -v BAR="${BAR[*]}" -v COLOR="
NR == 2 { maximum_brightness = $1 }
END {
brightness = ( current_brightness / maximum_brightness ) * 100
load = ( current_brightness / maximum_brightness ) * 100
if (LONG) {
printf("%d%\n%d\n", brightness, brightness)
printf("%d%\n%d\n", load, load)
} else {
for (i in bar) {
if (brightness <= i * interval) {
if (load <= i * interval) {
printf("%s\n%s\n", bar[i], bar[i])
break
}
}
}
for (i in bw) {
if (brightness <= i * interval) {
if (load <= i * interval) {
if (COLORS) {
printf("%s\n", color[i])
} else {

View File

@ -1,82 +0,0 @@
#!/bin/bash
DIR="/sys/class/power_supply"
[[ "$BLOCK_BUTTON" == "1" ]] && LONG=true
if [[ "$BLOCK_INSTANCE" == "" ]]; then
for BAT in $DIR/BAT*/; do
[[ -f "${BAT}uevent" ]] && BATS+="$BAT/uevent "
done
else
[[ -f "$DIR/BAT$BLOCK_INSTANCE/uevent" ]] && BATS="$DIR/BAT$BLOCK_INSTANCE/uevent"
fi
if [[ "$BATS" == "" ]]; then
echo " no battery "
echo "n/a"
exit 33
fi
cat $BATS | gawk -F '=' -v LONG="$LONG" '
BEGIN {
efull = 0
enow = 0
status = ""
}
/POWER_SUPPLY_STATUS=/ {
if (status == "") {
if ($2 == "Discharging") {
status = ""
} else if ($2 == "Charging") {
status = "⚡"
}
}
}
/POWER_SUPPLY_ENERGY_FULL=/ {
efull += $2
}
/POWER_SUPPLY_ENERGY_NOW=/ {
enow += $2
}
END {
charge = enow / efull * 100
if (LONG == "true") {
printf("%s%d%\n", status, charge)
} else {
if (charge < 100 / 9) {
printf("%s▁\n", status)
} else if (charge < 100 / 9 * 2 ) {
printf("%s▁\n", status)
} else if (charge < 100 / 9 * 3 ) {
printf("%s▂\n", status)
} else if (charge < 100 / 9 * 4 ) {
printf("%s▃\n", status)
} else if (charge < 100 / 9 * 5 ) {
printf("%s▄\n", status)
} else if (charge < 100 / 9 * 6 ) {
printf("%s▅\n", status)
} else if (charge < 100 / 9 * 7 ) {
printf("%s▆\n", status)
} else if (charge < 100 / 9 * 8 ) {
printf("%s▇\n", status)
} else {
printf("%s█\n", status)
}
}
printf("%s%d\n", status, charge)
if (charge > 25) {
print("#04B431\n")
} else if (charge > 20) {
print("#A8FF00\n")
} else if (charge > 15) {
print("#FFF600\n")
} else if (charge > 10) {
print("#FFAE00\n")
} else if (charge > 5) {
print("#FF0000\n")
} else {
exit 33
}
}
'

65
modules/battery.sh Executable file
View File

@ -0,0 +1,65 @@
DIR="/sys/class/power_supply"
if [[ "$BLOCK_INSTANCE" == "" ]]; then
for BAT in $DIR/BAT*/; do
[[ -f "${BAT}uevent" ]] && BATS+="$BAT/uevent "
done
else
[[ -f "$DIR/BAT$BLOCK_INSTANCE/uevent" ]] && BATS="$DIR/BAT$BLOCK_INSTANCE/uevent"
fi
if [[ "$BATS" == "" ]]; then
echo " no battery "
echo "n/a"
exit 33
fi
cat $BATS | gawk -v LONG="$LONG" -v COLORS="$COLORS" -v BAR="${BAR[*]}" -v COLOR="${COLOR[*]}" -v BW="${BW[*]}" -F "=" '
BEGIN {
split(BAR, bar, / /)
split(COLOR, color, / /)
split(BW, bw, / /)
interval = 100 / length(bar)
efull = 0
enow = 0
status = ""
}
/POWER_SUPPLY_STATUS=/ {
if (status == "") {
if ($2 == "Discharging") {
status = ""
} else if ($2 == "Charging") {
status = "⚡"
}
}
}
/POWER_SUPPLY_ENERGY_FULL=/ { efull += $2 }
/POWER_SUPPLY_ENERGY_NOW=/ { enow += $2 }
END {
load = enow / efull * 100
if (LONG) {
printf("%d%\n%d\n", load, load)
} else {
for (i in bar) {
if (load <= i * interval) {
printf("%s\n%s\n", bar[i], bar[i])
break
}
}
}
for (i in bw) {
if (load <= i * interval) {
if (COLORS) {
printf("%s\n", color[i])
} else {
printf("%s\n", bw[i])
}
break
}
}
}
'

View File

@ -1,49 +0,0 @@
#!/bin/bash
[[ "$BLOCK_INSTANCE" =~ "long" || "$BLOCK_BUTTON" == 1 ]] && LONG=true
[[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e htop
top -bn1 | gawk -v LONG="$LONG" '
/^\%CPU/ {
load = 100 - $8
}
END {
if (LONG == "true") {
printf("%d%\n%d%\n", load, 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 < 50) {
print("#04B431\n")
} else if (load < 60) {
print("#A8FF00\n")
} else if (load < 70) {
print("#FFF600\n")
} else if (load < 80) {
print("#FFAE00\n")
} else if (load < 90) {
print("#FF0000\n")
} else {
exit 33
}
}
'

35
modules/cpu.sh Executable file
View File

@ -0,0 +1,35 @@
[[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e htop
top -bn1 | gawk -v LONG="$LONG" -v COLORS="$COLORS" -v BAR="${BAR[*]}" -v COLOR="${COLOR[*]}" -v BW="${BW[*]}" '
BEGIN {
split(BAR, bar, / /)
split(COLOR, color, / /)
split(BW, bw, / /)
interval = 100 / length(bar)
}
/^\%CPU/ { load = 100 - $8 }
END {
if (LONG) {
printf("%d%\n%d\n", load, load)
} else {
for (i in bar) {
if (load <= i * interval) {
printf("%s\n%s\n", bar[i], bar[i])
break
}
}
}
for (i in bw) {
if (load <= i * interval) {
if (COLORS) {
printf("%s\n", color[i])
} else {
printf("%s\n", bw[i])
}
break
}
}
}
'

View File

@ -1,18 +0,0 @@
#!/bin/bash
toggle_long_instance () { [[ "$LONG" == "true" ]] && LONG=false || LONG=true; }
if [[ "$BLOCK_INSTANCE" =~ "pm" ]]; then
FULL=$(date '+%A %-d.%-m.%Y W%V, %-I:%M:%S%p')
SHORT=$(date '+%-I:%M%p')
else
FULL=$(date '+%A %-d.%-m.%Y W%V, %-H:%M:%S')
SHORT=$(date '+%-H:%M')
fi
[[ "$BLOCK_INSTANCE" =~ "long" ]] && toggle_long_instance
[[ "$BLOCK_BUTTON" == "1" ]] && toggle_long_instance
[[ "$LONG" == "true" ]] && echo $FULL || echo $SHORT
echo $SHORT

10
modules/datetime.sh Executable file
View File

@ -0,0 +1,10 @@
if [[ "$BLOCK_INSTANCE" =~ "pm" ]]; then
FULL=$(date '+%A %-d.%-m.%Y W%V, %-I:%M:%S%p')
SHORT=$(date '+%-I:%M%p')
else
FULL=$(date '+%A %-d.%-m.%Y W%V, %-H:%M:%S')
SHORT=$(date '+%-H:%M')
fi
[[ "$LONG" ]] && echo $FULL || echo $SHORT
echo $SHORT

View File

@ -1,5 +1,3 @@
#!/bin/bash
# Use the provided interface, otherwise the device used for the default route.
if [[ -n $BLOCK_INSTANCE ]]; then
IF=$BLOCK_INSTANCE

View File

@ -1,14 +1,6 @@
#!/bin/bash
# start firefox
[[ "$BLOCK_BUTTON" == 3 ]] && firefox
# get LONG status
if [[ "$BLOCK_BUTTON" == 1 ]]; then
[[ "$LONG" = true ]] && LONG=false || LONG=true
fi
[[ "$BLOCK_INSTANCE" =~ "long" ]] && LONG=true
# get interface
if [[ -n "$BLOCK_INSTANCE" ]]; then
IF="${BLOCK_INSTANCE#long}"
@ -18,13 +10,13 @@ fi
# check if network interface is empty
if [[ -z "$IF" ]]; then
[[ "$LONG" = true ]] && echo "No interface" || echo "n/a"
[[ $LONG ]] && echo "No interface" || echo "n/a"
exit 33
fi
# check if the network interface exists
if [[ ! -d "/sys/class/net/$IF" ]]; then
[[ "$LONG" = true ]] && echo "No interface" || echo "n/a"
[[ $LONG ]] && echo "No interface" || echo "n/a"
exit 33
fi
@ -40,19 +32,19 @@ if [[ "$LAN" =~ " UP " ]]; then
WAN_IP=$(curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
# check if internet connection is established
if [[ "$?" -eq 0 && $WAN_IP != "" ]]; then
if [[ "$LONG" = true ]]; then
if [[ $LONG ]]; then
echo $WAN_IP
echo $WAN_IP
echo "#04B431"
[[ $COLORS ]] && echo $COLOR[8] || echo $BW[8]
else
echo wan
echo wan
echo "#04B431"
echo WAN
echo WAN
[[ $COLORS ]] && echo $COLOR[8] || echo $BW[8]
fi
else
echo "lan"
fi
fi
else
[[ "$LONG" = true ]] && echo "$IF: off" || echo "off"
[[ $LONG ]] && echo "$IF: off" || echo "off"
fi

View File

@ -2,29 +2,35 @@
[[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e htop
[[ "$BLOCK_INSTANCE" =~ "long" || "$BLOCK_BUTTON" == 1 ]] && LONG=true
if [[ "$BLOCK_INSTANCE" =~ "ram" ]]; then
TYPE='ram'
elif [[ "$BLOCK_INSTANCE" =~ "swap" ]]; then
TYPE='swap'
fi
gawk -v TYPE="$TYPE" -v LONG="$LONG" '
/^MemTotal/ {
rtg = $2 / 1024^2
gawk -v TYPE="$TYPE" -v BAR="${BAR[*]}" -v BW="${BW[*]}" -v COLORS="$COLORS" -v COLOR="${COLOR[*]}" -v LONG="$LONG" '
BEGIN {
split(BAR, bar, / /)
split(COLOR, color, / /)
split(BW, bw, / /)
interval = 100 / length(bar)
}
/^MemTotal/ { rtg = $2 / 1024^2 }
/^MemAvailable/ {
rfg = $2 / 1024^2
rfm = $2 / 1024
}
/^SwapTotal/ {
stg = $2 / 1024^2
}
/^SwapTotal/ { stg = $2 / 1024^2 }
/^SwapFree/ {
sfg = $2 / 1024^2
sfm = $2 / 1024
}
END {
if (TYPE == "") {
mfg = rfg + sfg
@ -39,7 +45,8 @@ gawk -v TYPE="$TYPE" -v LONG="$LONG" '
mfm = sfm
rtg = stg
}
if (LONG == "true") {
load = (mtg - mfg) / mtg * 100
if (LONG) {
if (TYPE == "") {
if (mfg > 2) {
printf("%d+%d G\n", rfg, sfg)
@ -59,39 +66,22 @@ gawk -v TYPE="$TYPE" -v LONG="$LONG" '
}
}
} else {
load = 100 - mfg / mtg * 100
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")
for (i in bar) {
if (load <= i * interval) {
printf("%s\n%s\n", bar[i], bar[i])
break
}
}
}
for (i in bw) {
if (load <= i * interval) {
if (COLORS) {
printf("%s\n", color[i])
} else {
printf("%s\n", bw[i])
}
break
}
}
if (mfg > 5) {
print("#04B431\n")
} else if (mfg > 4) {
print("#A8FF00\n")
} else if (mfg > 3) {
print("#FFF600\n")
} else if (mfg > 2) {
print("#FFAE00\n")
} else if (mfg > 1) {
print("#FF0000\n")
} else {
exit 33
}
}
' /proc/meminfo

View File

@ -1,59 +0,0 @@
#!/bin/bash
[[ "$BLOCK_BUTTON" == 1 ]] && LONG=true
[[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e ranger
df | gawk -v LONG="$LONG" '
/\/$/ {
free_storage = $4 / 1024^2
load = gensub(/^([0-9]{1,3})%$/, "\\1", "g", $5)
}
END {
if (LONG == "true") {
if (free_storage < 1) {
printf(" full \n")
printf("full\n")
exit 33
} else if (free_storage > 5) {
printf("%.1f G\n", free_storage)
printf("%dG\n", free_storage)
} else {
printf("%.0f M\n", free_storage / 1024)
printf("%dM\n", free_storage / 1024)
}
} 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 (free_storage > 20) {
print("#04B431\n")
} else if (free_storage > 15) {
print("#A8FF00\n")
} else if (free_storage > 10) {
print("#FFF600\n")
} else if (free_storage > 5) {
print("#FFAE00\n")
} else if (free_storage > 1) {
print("#FF0000\n")
}
}
'

49
modules/storage.sh Executable file
View File

@ -0,0 +1,49 @@
[[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e ranger
df | gawk -v BAR="${BAR[*]}" -v BW="${BW[*]}" -v COLORS="$COLORS" -v COLOR="${COLOR[*]}" -v LONG="$LONG" '
BEGIN {
split(BAR, bar, / /)
split(COLOR, color, / /)
split(BW, bw, / /)
interval = 100 / length(bar)
}
/\/$/ {
free_storage = $4 / 1024^2
load = int(gensub(/^([0-9]{1,3})%$/, "\\1", "g", $5))
}
END {
if (LONG) {
if (free_storage < 1) {
printf(" full \n")
printf("full\n")
exit 33
} else if (free_storage > 5) {
printf("%.1f G\n", free_storage)
printf("%dG\n", free_storage)
} else {
printf("%.0f M\n", free_storage / 1024)
printf("%dM\n", free_storage / 1024)
}
} else {
for (i in bar) {
if (load <= i * interval) {
printf("%s\n%s\n", bar[i], bar[i])
break
}
}
}
for (i in bw) {
if (load <= i * interval) {
if (COLORS) {
printf("%s\n", color[i])
} else {
printf("%s\n", bw[i])
}
break
}
}
}
'

View File

@ -1,52 +0,0 @@
#!/bin/bash
[[ "$BLOCK_INSTANCE" =~ "long" || "$BLOCK_BUTTON" == 1 ]] && LONG=true
[[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e htop
sensors *-isa-* | awk -v LONG="$LONG" '
match($0, /^Package[^\+]*\+([0-9]{1,3})[^\+]*\+([0-9]{1,3})/, matches) {
temp = matches[1]
high = matches[2]
step = high / 8
tresholdc = 40
stepc = ( high - tresholdc ) / 6
}
END {
if (LONG == "true") {
printf("%d°C\n", temp)
printf("%d°C\n", temp)
} else {
if (temp < step) {
printf("▁\n▁\n")
} else if (temp < step * 2 ) {
printf("▂\n▂\n")
} else if (temp < step * 3 ) {
printf("▃\n▃\n")
} else if (temp < step * 4 ) {
printf("▄\n▄\n")
} else if (temp < step * 5 ) {
printf("▅\n▅\n")
} else if (temp < step * 6 ) {
printf("▆\n▆\n")
} else if (temp < step * 7 ) {
printf("▇\n▇\n")
} else {
printf("█\n█\n")
}
}
if (temp < stepc + tresholdc) {
print("#04B431\n")
} else if (temp < stepc * 2 + tresholdc) {
print("#A8FF00\n")
} else if (temp < stepc * 3 + tresholdc) {
print("#FFF600\n")
} else if (temp < stepc * 4 + tresholdc) {
print("#FFAE00\n")
} else if (temp < stepc * 5 + tresholdc) {
print("#FF0000\n")
} else {
exit 33
}
}
'

42
modules/temp.sh Executable file
View File

@ -0,0 +1,42 @@
[[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e htop
sensors *-isa-* | awk -v BAR="${BAR[*]}" -v BW="${BW[*]}" -v COLORS="$COLORS" -v COLOR="${COLOR[*]}" -v LONG="$LONG" '
BEGIN {
split(BAR, bar, / /)
split(COLOR, color, / /)
split(BW, bw, / /)
interval = 100 / length(bar)
}
match($0, /^Package[^\+]*\+([0-9]{1,3})[^\+]*\+([0-9]{1,3})/, matches) {
temp = matches[1]
high = matches[2]
step = high / 8
treshold = 40
load = (temp - treshold) / (high - treshold) * 100
}
END {
if (LONG) {
printf("%d°C\n%d°C\n", temp, temp)
} else {
for (i in bar) {
if (load <= i * interval) {
printf("%s\n%s\n", bar[i], bar[i])
break
}
}
}
for (i in bw) {
if (load <= i * interval) {
if (COLORS) {
printf("%s\n", color[i])
} else {
printf("%s\n", bw[i])
}
break
}
}
}
'