From d15787824f2aff0303633b79e50eb2bfe803608d Mon Sep 17 00:00:00 2001 From: tavo-wasd Date: Wed, 21 Feb 2024 18:53:01 -0600 Subject: [PATCH] apts & todos --- scripts/sway/swaystatus | 69 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/scripts/sway/swaystatus b/scripts/sway/swaystatus index 9293181..732703c 100755 --- a/scripts/sway/swaystatus +++ b/scripts/sway/swaystatus @@ -1,5 +1,50 @@ #!/bin/sh +get_int() { # Type of interface & status + # If active ethernet, just exit with icon + grep -xq 'up' /sys/class/net/e*/operstate 2>/dev/null && echo "󰛳" && return 0 + + # 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="──────────" ;; + 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 +} + +get_net() { + # Run 'int' + info=$(get_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 + [ -n "$vpn" ] && info="$(printf "$info" | sed 's/󰛳//' | sed 's/󰖩//')" + + # Print $info + printf "%s" "$info" +} + get_vol() { vol=$(amixer | grep "Playback" | grep -o '[0-9]*[0-9]%' | head -n 1) vol="${vol%\%*}" # Remove percentage sign @@ -52,10 +97,6 @@ get_mic() { echo " $bar" } -get_net() { - netstat -} - get_bat() { total=0 batteries=0 @@ -95,10 +136,28 @@ get_layout() { echo "󰌌 $layout" } +get_apts() { + apts="$(calcurse -a | grep -c '\*')" + [ "$apts" = "0" ] && return 0 + echo "󰃭 $apts" +} + +get_todo() { + todo="$(calcurse -t | wc -l)" + [ "$todo" = "0" ] && return 0 + echo " $todo" +} + while true ; do status="" separator=" " + todo="$(get_todo)" + ! [ -z "$todo" ] && status="$status$separator$todo" + + apts="$(get_apts)" + ! [ -z "$apts" ] && status="$status$separator$apts" + volume="$(get_vol)" ! [ -z "$volume" ] && status="$status$separator$volume" @@ -114,7 +173,7 @@ while true ; do layout="$(get_layout)" ! [ -z "$layout" ] && status="$status$separator$layout" - date_time="$(date "+%I:%M%p$separator󰃭 %a %Y-%m-%d")" + date_time="$(date "+%I:%M%p$separator󰃮 %a %Y-%m-%d")" ! [ -z "$date_time" ] && status="$status$separator󰥔 $date_time" printf "%s\n" "$status"