From 8047ecbd1f8ac66b47b2b7d10adac798096723ee Mon Sep 17 00:00:00 2001 From: tavo-wasd Date: Mon, 31 Jul 2023 02:51:39 -0600 Subject: [PATCH] better looking status bar modules! --- scripts/batstat | 22 +++++++++++++----- scripts/layoutstat | 3 ++- scripts/micstat | 27 ++++++++++++++++++---- scripts/netstat | 56 +++++++++++++++++++++++++++++++++++----------- scripts/nettraf | 17 ++++++++++++++ scripts/volstat | 31 ++++++++++++++++++++----- 6 files changed, 127 insertions(+), 29 deletions(-) create mode 100755 scripts/nettraf diff --git a/scripts/batstat b/scripts/batstat index ef936cc..546fba8 100755 --- a/scripts/batstat +++ b/scripts/batstat @@ -5,11 +5,23 @@ bat=$(grep "[0-9]" /sys/class/power_supply/BAT0/capacity) stat=$(cat /sys/class/power_supply/BAT0/status) -# Append charging indicator if status file indicates such state -# Print only charge % otherwise -[ "$stat" = "Charging" ] && - echo "$bat% " && exit || - echo "$bat%" +case 1 in + $((bat >= 98)) ) bar="━━━━━━━━━━" ;; + $((bat >= 90)) ) bar="━━━━━━━━━─" ;; + $((bat >= 80)) ) bar="━━━━━━━━──" ;; + $((bat >= 70)) ) bar="━━━━━━━───" ;; + $((bat >= 60)) ) bar="━━━━━━────" ;; + $((bat >= 50)) ) bar="━━━━━─────" ;; + $((bat >= 40)) ) bar="━━━━──────" ;; + $((bat >= 30)) ) bar="━━━───────" ;; + $((bat >= 20)) ) bar="━━────────" ;; + $((bat >= 10)) ) bar="━!────────" ;; + $((bat >= 0)) ) bar="CHARGE NOW" ;; +esac + +# Charging indicator if status file indicates such state +[ "$stat" != "Charging" ] && icon="󰁹" || icon="" +echo "$icon $bar" # Warning when battery is under 10% capacity and not charging [ $((bat)) -lt 15 ] && [ "$stat" != "Charging" ] && diff --git a/scripts/layoutstat b/scripts/layoutstat index 9199be1..42681fe 100755 --- a/scripts/layoutstat +++ b/scripts/layoutstat @@ -1,4 +1,5 @@ #!/bin/sh # Get current keyboard layout -setxkbmap -query | grep layout | awk '{print $2}' +setxkbmap -query | grep layout | awk '{print $2}' | + sed 's/latam/la/' diff --git a/scripts/micstat b/scripts/micstat index dc9ab41..d58edb9 100755 --- a/scripts/micstat +++ b/scripts/micstat @@ -4,12 +4,31 @@ # Get volume levels vol=$(amixer | grep "Capture" | grep -o '[0-9]*[0-9]%' | tail -n 1) +vol="${vol%\%*}" # Remove percentage sign # If device is off (muted), notify mute, print volume otherwise if amixer scontents | grep "Capture" | grep -q "\[off\]"; then - echo " M" + echo " ──────────" notify-send -u low --replace-id=11 " Microphone" "Mute" -else - echo "$vol" - notify-send -u low --replace-id=11 " Microphone" "$vol" + exit fi + +# Define bar progress with volume +case 1 in + $((vol >= 100)) ) bar="━━━━━━━━━━" ;; + $((vol >= 90)) ) bar="━━━━━━━━━─" ;; + $((vol >= 80)) ) bar="━━━━━━━━──" ;; + $((vol >= 70)) ) bar="━━━━━━━───" ;; + $((vol >= 60)) ) bar="━━━━━━────" ;; + $((vol >= 50)) ) bar="━━━━━─────" ;; + $((vol >= 40)) ) bar="━━━━──────" ;; + $((vol >= 30)) ) bar="━━━───────" ;; + $((vol >= 20)) ) bar="━━────────" ;; + $((vol >= 10)) ) bar="━─────────" ;; + $((vol >= 0)) ) bar="──────────" ;; + $((vol = 0)) ) bar="──────────" ;; +esac + +# Print and notify +echo " $bar" +notify-send -u low --replace-id=11 " Microphone" "$bar" diff --git a/scripts/netstat b/scripts/netstat index c9fec03..d72d2d1 100755 --- a/scripts/netstat +++ b/scripts/netstat @@ -1,17 +1,47 @@ #!/bin/sh -# Modified version of Luke Smith's network usage script -# Print cache so it doesn't get stuck in dwmblocks -cat "$XDG_CACHE_HOME"/netstat +int() { # Type of interface & status -# Store transferred and recieved bytes -rstart="$(($(cat /sys/class/net/[ew]*/statistics/rx_bytes | paste -sd '+')))" -tstart="$(($(cat /sys/class/net/[ew]*/statistics/tx_bytes | paste -sd '+')))" -sleep 1 -rend="$(($(cat /sys/class/net/[ew]*/statistics/rx_bytes | paste -sd '+')))" -tend="$(($(cat /sys/class/net/[ew]*/statistics/tx_bytes | paste -sd '+')))" + # If active ethernet, just exit with icon + grep -xq 'up' /sys/class/net/e*/operstate 2>/dev/null && echo "󰛳" && return 0 -# Format correctly and print -dow=$(printf "%2sB\n" "$(numfmt --to=iec $(($rend-$rstart)))") -up=$(printf "%2sB\n" "$(numfmt --to=iec $(($tend-$tstart)))") -printf "$dow|$up" | sed 's/ //g' > "$XDG_CACHE_HOME"/netstat + # If active WiFi, print link strength + if grep -xq 'up' /sys/class/net/w*/operstate 2>/dev/null ; then + strength="$(awk 'NR==3 {printf("%.0f\n",$3*10/7)}' /proc/net/wireless)" + case 1 in + $((strength >= 100)) ) bar="━━━━━━━━━━" ;; + $((strength >= 90)) ) bar="━━━━━━━━━─" ;; + $((strength >= 80)) ) bar="━━━━━━━━──" ;; + $((strength >= 70)) ) bar="━━━━━━━───" ;; + $((strength >= 60)) ) bar="━━━━━━────" ;; + $((strength >= 50)) ) bar="━━━━━─────" ;; + $((strength >= 40)) ) bar="━━━━──────" ;; + $((strength >= 30)) ) bar="━━━───────" ;; + $((strength >= 20)) ) bar="━━────────" ;; + $((strength >= 10)) ) bar="━─────────" ;; + $((strength >= 0)) ) bar="──────────" ;; + $((strength = 0)) ) bar="──────────" ;; + esac + echo "󰖩 $bar" + return 0 + fi + + # If down interfaces, exit with icon + grep -xq 'down' /sys/class/net/w*/operstate 2>/dev/null && echo "󰖪 ──────────" && return 0 + grep -xq 'down' /sys/class/net/e*/operstate 2>/dev/null && echo "󰲛" && return 0 + +} + +# Run 'int' +info=$(int) + +# Check if a VPN is enabled +vpn="$( \ + sed "s/.*//" /sys/class/net/tun*/operstate 2>/dev/null + sed "s/.*//" /sys/class/net/wg*/operstate 2>/dev/null \ + )" +# If so, change icon +[ -e "$vpn" ] && info="$(printf "$info" | sed 's/󰛳//' | sed 's/󰖩//')" + +# Print $info +printf "%s" "$info" diff --git a/scripts/nettraf b/scripts/nettraf new file mode 100755 index 0000000..c9fec03 --- /dev/null +++ b/scripts/nettraf @@ -0,0 +1,17 @@ +#!/bin/sh +# Modified version of Luke Smith's network usage script + +# Print cache so it doesn't get stuck in dwmblocks +cat "$XDG_CACHE_HOME"/netstat + +# Store transferred and recieved bytes +rstart="$(($(cat /sys/class/net/[ew]*/statistics/rx_bytes | paste -sd '+')))" +tstart="$(($(cat /sys/class/net/[ew]*/statistics/tx_bytes | paste -sd '+')))" +sleep 1 +rend="$(($(cat /sys/class/net/[ew]*/statistics/rx_bytes | paste -sd '+')))" +tend="$(($(cat /sys/class/net/[ew]*/statistics/tx_bytes | paste -sd '+')))" + +# Format correctly and print +dow=$(printf "%2sB\n" "$(numfmt --to=iec $(($rend-$rstart)))") +up=$(printf "%2sB\n" "$(numfmt --to=iec $(($tend-$tstart)))") +printf "$dow|$up" | sed 's/ //g' > "$XDG_CACHE_HOME"/netstat diff --git a/scripts/volstat b/scripts/volstat index 1e42fcd..57d8329 100755 --- a/scripts/volstat +++ b/scripts/volstat @@ -1,15 +1,34 @@ #!/bin/sh -# Fetch current audio levels +# Fetch current audio level # (in current default output) -# Get volume levels +# Get volume level vol=$(amixer | grep "Playback" | grep -o '[0-9]*[0-9]%' | head -n 1) +vol="${vol%\%*}" # Remove percentage sign # If device is off (muted), notify mute, print volume otherwise if amixer scontents | grep "Playback" | grep -q "\[off\]"; then - echo " M" + echo "󰖁 ──────────" notify-send -u low --replace-id=10 "󰖁 Volume" "Mute" -else - echo "$vol" - notify-send -u low --replace-id=10 "󰕾 Volume" "$vol" + exit fi + +# Define bar progress with volume +case 1 in + $((vol >= 100)) ) bar="━━━━━━━━━━" ;; + $((vol >= 90)) ) bar="━━━━━━━━━─" ;; + $((vol >= 80)) ) bar="━━━━━━━━──" ;; + $((vol >= 70)) ) bar="━━━━━━━───" ;; + $((vol >= 60)) ) bar="━━━━━━────" ;; + $((vol >= 50)) ) bar="━━━━━─────" ;; + $((vol >= 40)) ) bar="━━━━──────" ;; + $((vol >= 30)) ) bar="━━━───────" ;; + $((vol >= 20)) ) bar="━━────────" ;; + $((vol >= 10)) ) bar="━─────────" ;; + $((vol >= 0)) ) bar="──────────" ;; + $((vol = 0)) ) bar="──────────" ;; +esac + +# Print and notify +echo "󰕾 $bar" +notify-send -u low --replace-id=10 "󰕾 Volume" "$bar"