diff options
author | zachir <zachir@librem.one> | 2022-10-09 01:25:20 -0500 |
---|---|---|
committer | zachir <zachir@librem.one> | 2022-10-09 01:25:20 -0500 |
commit | 91e4799fedf9dbff384003b8c2eaea039cb57327 (patch) | |
tree | f7b017919dbce7a69ac28e3388371ad1fc8ca6d9 |
initialize repo
-rwxr-xr-x | battery | 21 | ||||
-rwxr-xr-x | clock | 12 | ||||
-rwxr-xr-x | cpu | 16 | ||||
-rwxr-xr-x | disk | 20 | ||||
-rwxr-xr-x | internet | 18 | ||||
-rwxr-xr-x | memory | 12 | ||||
-rwxr-xr-x | music | 24 | ||||
-rwxr-xr-x | nettraf | 28 | ||||
-rwxr-xr-x | volume | 23 |
9 files changed, 174 insertions, 0 deletions
@@ -0,0 +1,21 @@ +#!/sbin/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/ *$//' @@ -0,0 +1,12 @@ +#!/sbin/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 @@ +#!/sbin/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 @@ +#!/sbin/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/internet b/internet new file mode 100755 index 0000000..5850a13 --- /dev/null +++ b/internet @@ -0,0 +1,18 @@ +#!/sbin/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)" @@ -0,0 +1,12 @@ +#!/sbin/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))}' @@ -0,0 +1,24 @@ +#!/sbin/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 @@ -0,0 +1,28 @@ +#!/sbin/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" @@ -0,0 +1,23 @@ +#!/sbin/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 "[%s]" "$vol" |