From 451dd44eac15c62b163bc7036501ccd4e3a218a6 Mon Sep 17 00:00:00 2001 From: koksnuss Date: Fri, 10 Aug 2018 15:13:31 +0200 Subject: [PATCH] refractor: move code to abstract.sh enable unique and central color palette and progress bar --- README.md | 30 ++++++++--- config | 4 +- modules/abstract.sh | 10 ++++ modules/audio | 60 --------------------- modules/audio.sh | 46 ++++++++++++++++ modules/{backlight => backlight.sh} | 19 ++----- modules/battery | 82 ----------------------------- modules/battery.sh | 65 +++++++++++++++++++++++ modules/cpu | 49 ----------------- modules/cpu.sh | 35 ++++++++++++ modules/datetime | 18 ------- modules/datetime.sh | 10 ++++ modules/{iface => iface.sh} | 2 - modules/{ip => ip.sh} | 24 +++------ modules/{ram => ram.sh} | 72 +++++++++++-------------- modules/storage | 59 --------------------- modules/storage.sh | 49 +++++++++++++++++ modules/temp | 52 ------------------ modules/temp.sh | 42 +++++++++++++++ 19 files changed, 325 insertions(+), 403 deletions(-) create mode 100755 modules/abstract.sh delete mode 100755 modules/audio create mode 100755 modules/audio.sh rename modules/{backlight => backlight.sh} (59%) delete mode 100755 modules/battery create mode 100755 modules/battery.sh delete mode 100755 modules/cpu create mode 100755 modules/cpu.sh delete mode 100755 modules/datetime create mode 100755 modules/datetime.sh rename modules/{iface => iface.sh} (98%) rename modules/{ip => ip.sh} (64%) rename modules/{ram => ram.sh} (50%) delete mode 100755 modules/storage create mode 100755 modules/storage.sh delete mode 100755 modules/temp create mode 100755 modules/temp.sh diff --git a/README.md b/README.md index 362056f..1d3364c 100644 --- a/README.md +++ b/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] 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 diff --git a/config b/config index a669528..aa6a2d5 100644 --- a/config +++ b/config @@ -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] diff --git a/modules/abstract.sh b/modules/abstract.sh new file mode 100755 index 0000000..f370395 --- /dev/null +++ b/modules/abstract.sh @@ -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 + + diff --git a/modules/audio b/modules/audio deleted file mode 100755 index 37be3f6..0000000 --- a/modules/audio +++ /dev/null @@ -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 - } - } - } -' diff --git a/modules/audio.sh b/modules/audio.sh new file mode 100755 index 0000000..b634460 --- /dev/null +++ b/modules/audio.sh @@ -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 + } + } + } + } +' diff --git a/modules/backlight b/modules/backlight.sh similarity index 59% rename from modules/backlight rename to modules/backlight.sh index 7092405..c2d2406 100755 --- a/modules/backlight +++ b/modules/backlight.sh @@ -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 { diff --git a/modules/battery b/modules/battery deleted file mode 100755 index 680f30d..0000000 --- a/modules/battery +++ /dev/null @@ -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 - } - } -' diff --git a/modules/battery.sh b/modules/battery.sh new file mode 100755 index 0000000..f6f2175 --- /dev/null +++ b/modules/battery.sh @@ -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 + } + } + } +' diff --git a/modules/cpu b/modules/cpu deleted file mode 100755 index 9f00cd3..0000000 --- a/modules/cpu +++ /dev/null @@ -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 - } - } -' diff --git a/modules/cpu.sh b/modules/cpu.sh new file mode 100755 index 0000000..dbc1e55 --- /dev/null +++ b/modules/cpu.sh @@ -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 + } + } + } +' diff --git a/modules/datetime b/modules/datetime deleted file mode 100755 index e65cf89..0000000 --- a/modules/datetime +++ /dev/null @@ -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 diff --git a/modules/datetime.sh b/modules/datetime.sh new file mode 100755 index 0000000..b60d7bd --- /dev/null +++ b/modules/datetime.sh @@ -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 diff --git a/modules/iface b/modules/iface.sh similarity index 98% rename from modules/iface rename to modules/iface.sh index 07bcb25..b797cf1 100755 --- a/modules/iface +++ b/modules/iface.sh @@ -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 diff --git a/modules/ip b/modules/ip.sh similarity index 64% rename from modules/ip rename to modules/ip.sh index e6c3958..357a245 100755 --- a/modules/ip +++ b/modules/ip.sh @@ -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 diff --git a/modules/ram b/modules/ram.sh similarity index 50% rename from modules/ram rename to modules/ram.sh index 8757775..8b18b8a 100755 --- a/modules/ram +++ b/modules/ram.sh @@ -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 diff --git a/modules/storage b/modules/storage deleted file mode 100755 index daa9b0e..0000000 --- a/modules/storage +++ /dev/null @@ -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") - } - } -' diff --git a/modules/storage.sh b/modules/storage.sh new file mode 100755 index 0000000..df26c4e --- /dev/null +++ b/modules/storage.sh @@ -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 + } + } + } +' diff --git a/modules/temp b/modules/temp deleted file mode 100755 index cbbe6ae..0000000 --- a/modules/temp +++ /dev/null @@ -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 - } - } -' diff --git a/modules/temp.sh b/modules/temp.sh new file mode 100755 index 0000000..8ab208e --- /dev/null +++ b/modules/temp.sh @@ -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 + } + } + } +'