diff options
-rwxr-xr-x | sb-backlight | 19 | ||||
-rwxr-xr-x | sb-battery | 21 | ||||
-rwxr-xr-x | sb-clock | 12 | ||||
-rwxr-xr-x | sb-cpu | 16 | ||||
-rwxr-xr-x | sb-disk | 20 | ||||
-rwxr-xr-x | sb-internet | 18 | ||||
-rwxr-xr-x | sb-memory | 12 | ||||
-rwxr-xr-x | sb-music | 24 | ||||
-rwxr-xr-x | sb-nettraf | 28 | ||||
-rwxr-xr-x | sb-volume | 23 |
10 files changed, 193 insertions, 0 deletions
diff --git a/sb-backlight b/sb-backlight new file mode 100755 index 0000000..aba0945 --- /dev/null +++ b/sb-backlight @@ -0,0 +1,19 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) + pgrep -x pipewire >/dev/null && MIXER="pulsemixer" || \ + pgrep -x pulseaudio >/dev/null && MIXER="pulsemixer" || \ + MIXER="alsamixer" + setsid -f $TERMINAL -e $MIXER + ;; + 2) notify-send "Volume module" "\- Shows volume, X if muted. +- Middle click to show this message. +- Right click to mute. +- Scroll to change." ;; + 3) volsv -t ;; + 4) volsv -i ;; + 5) volsv -d ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac +printf "[%3.0f%%]" "$(bl -g)" diff --git a/sb-battery b/sb-battery new file mode 100755 index 0000000..28c0b36 --- /dev/null +++ b/sb-battery @@ -0,0 +1,21 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 2) notify-send "Battery module" "- : discharging +X : not charging +? : unknown ++ : charging +| : charged +! : battery very low!" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +ls /sys/class/power_supply/ | grep -i bat | head -1 | while read battery; +do + capacity=$(cat "/sys/class/power_supply/$battery"/capacity) || break + status=$(sed "s/[Dd]ischarging/-/;s/[Nn]ot charging/X/;s/[Cc]harging/+/;s/[Uu]nknown/?/;s/[Ff]ull/|/" "/sys/class/power_supply/$battery"/status) + + [ "$capacity" -le 25 ] && [ "$status" = "!" ] && warn="!" + printf "[%s%s%s]" "$status" "$warn" "$capacity" + unset warn +done | sed 's/ *$//' diff --git a/sb-clock b/sb-clock new file mode 100755 index 0000000..cc6b0d9 --- /dev/null +++ b/sb-clock @@ -0,0 +1,12 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) notify-send "This Month" "$(cal --color=always | sed "s/..7m/<b><span color=\"red\">/;s/..27m/<\/spawn<\/b>/")" && notify-send "Appointments" "$(calcurse -D ~/.config/calcurse -d3)" ;; + 2) notify-send "Time/date module" "\- Left click to show upcoming appointmnets for the next three days via \`calcurse -d3\` and show the month via \`cal\` +- Middle click to show this message +- Right click to open calcurse" ;; + 3) setsid -f "$TERMINAL" -e calcurse -D ~/.config/calcurse ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +printf "[%s]" "$(date "+%Y %b %d (%a) %I:%M%p")" @@ -0,0 +1,16 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) notify-send "CPU hogs" "$(ps axch -o comm,%cpu --sort=-%cpu | head)\\n(100% per core)" ;; + 2) notify-send "CPU module" "\- Shows CPU usage. +- Click to show intensive progresses. +- Middle click to show this tip +- Right click to open htop" ;; + 3) setsid -f "$TERMINAL" -e htop ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +usage=$(mpstat 1 1 | sed '1,4d;s/.* //') +output="$(echo $usage | awk '{printf ("%2.2f", (100 - $1))}' | cut -c-4)" +echo -n "[$output%]" + @@ -0,0 +1,20 @@ +#!/bin/sh + +location=${1:-/} + +[ -d "$location" ] || exit + +case $BLOCK_BUTTON in + 1) notify-send "💽 Disk space" "$(df -h --output=target,used,size)" ;; + 3) notify-send "💽 Disk module" "\- Shows used hard drive space. +- Click to show all disk info." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +case "$location" in + "/home"* ) icon="h" ;; + "/mnt"* ) icon="m" ;; + *) icon="s";; +esac + +printf "[%s: %s]" "$icon" "$(df -h "$location" | awk ' /[0-9]/ {print $3 "/" $2}')" diff --git a/sb-internet b/sb-internet new file mode 100755 index 0000000..8dfd24f --- /dev/null +++ b/sb-internet @@ -0,0 +1,18 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) "$TERMINAL" -e nmtui; pkill -RTMIN+4 dwmblocks ;; + 2) notify-send "Internet module" "\- Click to connect +X : no wifi connection ++ : wifi connection +_ : no ethernet +- : ethernet working" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +case "$(cat /sys/class/net/w*/operstate 2>/dev/null)" in + down) wifiicon="X" ;; + up) wifiicon="$(awk '/^\s*w/ { print "+", int($3 * 100 / 70) "% " }' /proc/net/wireless)" ;; +esac + +printf "[%s%s]" "$wifiicon" "$(sed "s/down/_/;s/up/-/" /sys/class/net/e*/operstate 2>/dev/null)" diff --git a/sb-memory b/sb-memory new file mode 100755 index 0000000..8b81626 --- /dev/null +++ b/sb-memory @@ -0,0 +1,12 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) notify-send "Memory hogs" "$(ps axch -o cmd:15,%mem --sort=-%mem | head)" ;; + 2) notify-send "Memory module" "\- Shows Memory Used/Total. +- Click to show memory hogs. +- Right click to open htop." ;; + 3) setsid -f "$TERMINAL" -e htop ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +free --mebi | sed -n '2{p;q}' | awk '{printf ("[%2.2fGiB/%2.2fGiB]", ( $3 / 1024), ($2 / 1024))}' diff --git a/sb-music b/sb-music new file mode 100755 index 0000000..22a41c8 --- /dev/null +++ b/sb-music @@ -0,0 +1,24 @@ +#!/bin/sh + +filter() { + if [ `pgrep -x mpd` ]; then + MPCSTAT="$(mpc status)" ; + printf "%s%s%s" "$(echo $MPCSTAT | head -1 | grep -v '^volume' | cut -d'-' -f1 | sed 's/ $//' | cut -c-10)" "$(echo $MPCSTAT | grep -vq '^volume' && echo ' - ')" "$(echo $MPCSTAT | head -1 | grep -v '^volume' | cut -d'-' -f2 | sed 's/^ //' | cut -c-10)" + fi +} + +pidof -x mpdup >/dev/null 2>&1 || mpdup >/dev/null 2>&1 & + +case $BLOCK_BUTTON in + 1) mpc status | filter ; setsid -f "$TERMINAL" -e ncmpcpp ;; # left click, open music player + 3) mpc toggle | filter ;; # right click, pause/unpause + 2) mpc status | filter ; notify-send "🎵 Music module" "\- Shows mpd song playing. +- Italic when paused. +- Left click opens ncmpcpp. +- Middle click pauses. +- Scroll changes track.";; # right click, pause/unpause + 4) mpc prev | filter ;; # scroll up, previous + 5) mpc next | filter ;; # scroll down, next + 6) mpc status | filter ; "$TERMINAL" -e "$EDITOR" "$0" ;; + *) filter ;; +esac diff --git a/sb-nettraf b/sb-nettraf new file mode 100755 index 0000000..ac43416 --- /dev/null +++ b/sb-nettraf @@ -0,0 +1,28 @@ +#!/bin/sh + +# Module showing network traffic. Shows how much data has been received (RX) or +# transmitted (TX) since the previous time this script ran. So if run every +# second, gives network traffic per second. + +case $BLOCK_BUTTON in + 3) notify-send "🌐 Network traffic module" "🔻: Traffic received +🔺: Traffic transmitted" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +update() { + sum=0 + for arg; do + read -r i < "$arg" + sum=$(( sum + i )) + done + cache=${XDG_CACHE_HOME:-$HOME/.cache}/${1##*/} + [ -f "$cache" ] && read -r old < "$cache" || old=0 + printf %d\\n "$sum" > "$cache" + printf %d\\n $(( (sum - old) / 1024 )) +} + +rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes) +tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes) + +printf "🔻%dKiB 🔺%dKiB\\n" "$rx" "$tx" diff --git a/sb-volume b/sb-volume new file mode 100755 index 0000000..03c9e0b --- /dev/null +++ b/sb-volume @@ -0,0 +1,23 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) + pgrep -x pipewire >/dev/null && MIXER="pulsemixer" || \ + pgrep -x pulseaudio >/dev/null && MIXER="pulsemixer" || \ + MIXER="alsamixer" + setsid -f $TERMINAL -e $MIXER + ;; + 2) notify-send "Volume module" "\- Shows volume, X if muted. +- Middle click to show this message. +- Right click to mute. +- Scroll to change." ;; + 3) volsv -t ;; + 4) volsv -i ;; + 5) volsv -d ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac +volstat="$(volsv -v)" +mutstat="$(volsv -g)" +echo "$mutstat" | grep -q "off" && printf "[X]" && exit +vol="$(echo "$volstat" | grep '[0-9]\+%' | sed "s,.* \([0-9]\+\)%.*,\1,;1q")" +printf "[%4s]" "$vol" |