diff --git a/modules/1 b/modules/1 deleted file mode 100644 index 9689bf5..0000000 --- a/modules/1 +++ /dev/null @@ -1 +0,0 @@ -71 2 diff --git a/modules/abstract.sh b/modules/abstract.sh index 0240d95..013c8b9 100755 --- a/modules/abstract.sh +++ b/modules/abstract.sh @@ -1,6 +1,7 @@ [[ "$BLOCK_INSTANCE" =~ "color" ]] && COLORS=True [[ "$BLOCK_INSTANCE" =~ "long" || "$BLOCK_BUTTON" == 1 ]] && LONG=True +EXIT=False BAR=("▁" "▂" "▃" "▄" "▅" "▆" "▇" "█") INTERVAL=$((100 / ${#BAR[@]})) COLOR=("#64bc01" "#77a601" "#8a9101" "#9d7b00" "#b06701" "#c45100" "#d63c00" "#e92700") @@ -9,7 +10,7 @@ BW=("#565656" "#6d6d6d" "#848485" "#9c9c9c" "#b1b1b1" "#c7c7c7" "#dcdcdc" "#f5f5 source $HOME/.config/i3blocks/modules/${1}.sh # text -if [[ "$LONG" ]]; then +if [[ "$LONG" || "$LONG_TEXT" == "off" ]]; then echo "$LONG_TEXT" echo "$SHORT_TEXT" else diff --git a/modules/audio.sh b/modules/audio.sh index b634460..ed783c7 100644 --- a/modules/audio.sh +++ b/modules/audio.sh @@ -2,45 +2,18 @@ [[ "$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 - } - } - } - } -' +if [[ $(amixer get $DEV) =~ \[([0-9]+)\%\][[:space:]]\[(on|off)\] ]]; then + LOAD=${BASH_REMATCH[1]} + STATE=${BASH_REMATCH[2]} + if [[ "$STATE" == "on" ]]; then + LONG_TEXT="${LOAD}%" + SHORT_TEXT="${LOAD}" + else + LONG_TEXT="off" + SHORT_TEXT="X" + EXIT=True + fi +else + LONG_TEXT="no audio source" + SHORT_TEXT="n/a" +fi diff --git a/modules/cpu.sh b/modules/cpu.sh index dbc1e55..aa17fe0 100644 --- a/modules/cpu.sh +++ b/modules/cpu.sh @@ -1,35 +1,6 @@ [[ "$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 - } - } - } -' +IDLE=$(top -bn1 | head -3 | grep -Eo [0-9]+,[0-9][[:space:]]id | grep -Eo [0-9]+ | head -1) +LOAD=$((100 - $IDLE)) +LONG_TEXT="$LOAD%" +SHORT_TEXT="$LOAD"