refractor: move code to abstract.sh enable unique and central color palette and progress bar
This commit is contained in:
parent
11f963804e
commit
451dd44eac
30
README.md
30
README.md
@ -53,21 +53,35 @@ One-Liner: Open up a terminal and paste: `bash <(curl -s https://will.kein.hk/gi
|
|||||||
- [x] battery
|
- [x] battery
|
||||||
- [x] backlight
|
- [x] backlight
|
||||||
- [ ] wifi/ethernet/bluetooth
|
- [ ] wifi/ethernet/bluetooth
|
||||||
- [ ] external storage
|
- [ ] mount
|
||||||
- [ ] ethernet bandwith
|
- [ ] 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
|
## Click interactions
|
||||||
- [x] general: left: toggle long preview
|
|
||||||
- [x] audio/mic: middle: open pavucontrol, right: toggle mute
|
### Long/Short preview: Middle click
|
||||||
- [x] ram/cpu/temp: middle: open htop
|
- [ ] Toggle long (numbers and units) and short (representative bar) preview
|
||||||
- [x] storage: middle: open ranger
|
|
||||||
- [x] ip: middle: open firefox
|
### Open another program: Left click
|
||||||
- [ ] external storage: mount it somewhere
|
- [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
|
## Signals
|
||||||
- [x] audio, mic
|
- [x] audio, mic
|
||||||
- [ ] backlight
|
- [ ] backlight
|
||||||
|
- [ ] mount
|
||||||
|
|
||||||
## Other
|
## Other features
|
||||||
- [x] nice icons as labels
|
- [x] nice icons as labels
|
||||||
- [x] showing percentage values as a vertical bar
|
- [x] showing percentage values as a vertical bar
|
||||||
|
4
config
4
config
@ -2,14 +2,14 @@
|
|||||||
markup=none
|
markup=none
|
||||||
separator_block_width=15
|
separator_block_width=15
|
||||||
separator=false
|
separator=false
|
||||||
command=$HOME/.config/i3blocks/modules/$BLOCK_NAME
|
command=$HOME/.config/i3blocks/modules/abstract.sh $BLOCK_NAME
|
||||||
interval=5
|
interval=5
|
||||||
|
|
||||||
[backlight]
|
[backlight]
|
||||||
label=☼
|
label=☼
|
||||||
# label=☀,☼,✱,✲,✳,✴,✵,✺
|
# label=☀,☼,✱,✲,✳,✴,✵,✺
|
||||||
signal=3
|
signal=3
|
||||||
instance=color,long
|
instance=long
|
||||||
# instance=color,bw,long
|
# instance=color,bw,long
|
||||||
|
|
||||||
# [iface]
|
# [iface]
|
||||||
|
10
modules/abstract.sh
Executable file
10
modules/abstract.sh
Executable 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
|
||||||
|
|
||||||
|
|
@ -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
46
modules/audio.sh
Executable 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'
|
@ -1,9 +1,4 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
DIR="/sys/class/backlight"
|
DIR="/sys/class/backlight"
|
||||||
[[ "$BLOCK_INSTANCE" =~ "color" ]] && COLORS=True
|
|
||||||
[[ "$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"
|
||||||
elif [[ -d "$DIR/intel_backlight" ]]; then
|
elif [[ -d "$DIR/intel_backlight" ]]; then
|
||||||
@ -13,11 +8,7 @@ else
|
|||||||
exit 33
|
exit 33
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BAR=("▁" "▂" "▃" "▄" "▅" "▆" "▇" "█")
|
cat "$DIR/brightness" "$DIR/max_brightness" | gawk -v BAR="${BAR[*]}" -v BW="${BW[*]}" -v COLORS="$COLORS" -v COLOR="${COLOR[*]}" -v LONG="$LONG" '
|
||||||
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" '
|
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
split(BAR, bar, / /)
|
split(BAR, bar, / /)
|
||||||
@ -30,19 +21,19 @@ cat "$DIR/brightness" "$DIR/max_brightness" | gawk -v BAR="${BAR[*]}" -v COLOR="
|
|||||||
NR == 2 { maximum_brightness = $1 }
|
NR == 2 { maximum_brightness = $1 }
|
||||||
|
|
||||||
END {
|
END {
|
||||||
brightness = ( current_brightness / maximum_brightness ) * 100
|
load = ( current_brightness / maximum_brightness ) * 100
|
||||||
if (LONG) {
|
if (LONG) {
|
||||||
printf("%d%\n%d\n", brightness, brightness)
|
printf("%d%\n%d\n", load, load)
|
||||||
} else {
|
} else {
|
||||||
for (i in bar) {
|
for (i in bar) {
|
||||||
if (brightness <= i * interval) {
|
if (load <= i * interval) {
|
||||||
printf("%s\n%s\n", bar[i], bar[i])
|
printf("%s\n%s\n", bar[i], bar[i])
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i in bw) {
|
for (i in bw) {
|
||||||
if (brightness <= i * interval) {
|
if (load <= i * interval) {
|
||||||
if (COLORS) {
|
if (COLORS) {
|
||||||
printf("%s\n", color[i])
|
printf("%s\n", color[i])
|
||||||
} else {
|
} else {
|
@ -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
65
modules/battery.sh
Executable 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'
|
49
modules/cpu
49
modules/cpu
@ -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
35
modules/cpu.sh
Executable 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'
|
@ -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
10
modules/datetime.sh
Executable 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
|
@ -1,5 +1,3 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Use the provided interface, otherwise the device used for the default route.
|
# Use the provided interface, otherwise the device used for the default route.
|
||||||
if [[ -n $BLOCK_INSTANCE ]]; then
|
if [[ -n $BLOCK_INSTANCE ]]; then
|
||||||
IF=$BLOCK_INSTANCE
|
IF=$BLOCK_INSTANCE
|
@ -1,14 +1,6 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# start firefox
|
# start firefox
|
||||||
[[ "$BLOCK_BUTTON" == 3 ]] && 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
|
# get interface
|
||||||
if [[ -n "$BLOCK_INSTANCE" ]]; then
|
if [[ -n "$BLOCK_INSTANCE" ]]; then
|
||||||
IF="${BLOCK_INSTANCE#long}"
|
IF="${BLOCK_INSTANCE#long}"
|
||||||
@ -18,13 +10,13 @@ fi
|
|||||||
|
|
||||||
# check if network interface is empty
|
# check if network interface is empty
|
||||||
if [[ -z "$IF" ]]; then
|
if [[ -z "$IF" ]]; then
|
||||||
[[ "$LONG" = true ]] && echo "No interface" || echo "n/a"
|
[[ $LONG ]] && echo "No interface" || echo "n/a"
|
||||||
exit 33
|
exit 33
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check if the network interface exists
|
# check if the network interface exists
|
||||||
if [[ ! -d "/sys/class/net/$IF" ]]; then
|
if [[ ! -d "/sys/class/net/$IF" ]]; then
|
||||||
[[ "$LONG" = true ]] && echo "No interface" || echo "n/a"
|
[[ $LONG ]] && echo "No interface" || echo "n/a"
|
||||||
exit 33
|
exit 33
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -40,19 +32,19 @@ if [[ "$LAN" =~ " UP " ]]; then
|
|||||||
WAN_IP=$(curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
|
WAN_IP=$(curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
|
||||||
# check if internet connection is established
|
# check if internet connection is established
|
||||||
if [[ "$?" -eq 0 && $WAN_IP != "" ]]; then
|
if [[ "$?" -eq 0 && $WAN_IP != "" ]]; then
|
||||||
if [[ "$LONG" = true ]]; then
|
if [[ $LONG ]]; then
|
||||||
echo $WAN_IP
|
echo $WAN_IP
|
||||||
echo $WAN_IP
|
echo $WAN_IP
|
||||||
echo "#04B431"
|
[[ $COLORS ]] && echo $COLOR[8] || echo $BW[8]
|
||||||
else
|
else
|
||||||
echo wan
|
echo WAN
|
||||||
echo wan
|
echo WAN
|
||||||
echo "#04B431"
|
[[ $COLORS ]] && echo $COLOR[8] || echo $BW[8]
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "lan"
|
echo "lan"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
[[ "$LONG" = true ]] && echo "$IF: off" || echo "off"
|
[[ $LONG ]] && echo "$IF: off" || echo "off"
|
||||||
fi
|
fi
|
@ -2,29 +2,35 @@
|
|||||||
|
|
||||||
[[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e htop
|
[[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e htop
|
||||||
|
|
||||||
[[ "$BLOCK_INSTANCE" =~ "long" || "$BLOCK_BUTTON" == 1 ]] && LONG=true
|
|
||||||
|
|
||||||
if [[ "$BLOCK_INSTANCE" =~ "ram" ]]; then
|
if [[ "$BLOCK_INSTANCE" =~ "ram" ]]; then
|
||||||
TYPE='ram'
|
TYPE='ram'
|
||||||
elif [[ "$BLOCK_INSTANCE" =~ "swap" ]]; then
|
elif [[ "$BLOCK_INSTANCE" =~ "swap" ]]; then
|
||||||
TYPE='swap'
|
TYPE='swap'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
gawk -v TYPE="$TYPE" -v LONG="$LONG" '
|
gawk -v TYPE="$TYPE" -v BAR="${BAR[*]}" -v BW="${BW[*]}" -v COLORS="$COLORS" -v COLOR="${COLOR[*]}" -v LONG="$LONG" '
|
||||||
/^MemTotal/ {
|
|
||||||
rtg = $2 / 1024^2
|
BEGIN {
|
||||||
|
split(BAR, bar, / /)
|
||||||
|
split(COLOR, color, / /)
|
||||||
|
split(BW, bw, / /)
|
||||||
|
interval = 100 / length(bar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/^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
|
/^SwapTotal/ { stg = $2 / 1024^2 }
|
||||||
}
|
|
||||||
/^SwapFree/ {
|
/^SwapFree/ {
|
||||||
sfg = $2 / 1024^2
|
sfg = $2 / 1024^2
|
||||||
sfm = $2 / 1024
|
sfm = $2 / 1024
|
||||||
}
|
}
|
||||||
|
|
||||||
END {
|
END {
|
||||||
if (TYPE == "") {
|
if (TYPE == "") {
|
||||||
mfg = rfg + sfg
|
mfg = rfg + sfg
|
||||||
@ -39,7 +45,8 @@ gawk -v TYPE="$TYPE" -v LONG="$LONG" '
|
|||||||
mfm = sfm
|
mfm = sfm
|
||||||
rtg = stg
|
rtg = stg
|
||||||
}
|
}
|
||||||
if (LONG == "true") {
|
load = (mtg - mfg) / mtg * 100
|
||||||
|
if (LONG) {
|
||||||
if (TYPE == "") {
|
if (TYPE == "") {
|
||||||
if (mfg > 2) {
|
if (mfg > 2) {
|
||||||
printf("%d+%d G\n", rfg, sfg)
|
printf("%d+%d G\n", rfg, sfg)
|
||||||
@ -59,39 +66,22 @@ gawk -v TYPE="$TYPE" -v LONG="$LONG" '
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
load = 100 - mfg / mtg * 100
|
for (i in bar) {
|
||||||
if (load < 100 / 9) {
|
if (load <= i * interval) {
|
||||||
printf("▁\n▁\n")
|
printf("%s\n%s\n", bar[i], bar[i])
|
||||||
} else if (load < 100 / 9 * 2 ) {
|
break
|
||||||
printf("▁\n▁\n")
|
}
|
||||||
} else if (load < 100 / 9 * 3 ) {
|
}
|
||||||
printf("▂\n▂\n")
|
}
|
||||||
} else if (load < 100 / 9 * 4 ) {
|
for (i in bw) {
|
||||||
printf("▃\n▃\n")
|
if (load <= i * interval) {
|
||||||
} else if (load < 100 / 9 * 5 ) {
|
if (COLORS) {
|
||||||
printf("▄\n▄\n")
|
printf("%s\n", color[i])
|
||||||
} else if (load < 100 / 9 * 6 ) {
|
} else {
|
||||||
printf("▅\n▅\n")
|
printf("%s\n", bw[i])
|
||||||
} else if (load < 100 / 9 * 7 ) {
|
}
|
||||||
printf("▆\n▆\n")
|
break
|
||||||
} else if (load < 100 / 9 * 8 ) {
|
|
||||||
printf("▇\n▇\n")
|
|
||||||
} else {
|
|
||||||
printf("█\n█\n")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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
|
' /proc/meminfo
|
@ -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
49
modules/storage.sh
Executable 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'
|
52
modules/temp
52
modules/temp
@ -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
42
modules/temp.sh
Executable 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'
|
Reference in New Issue
Block a user