diff options
| author | Daniel <[email protected]> | 2024-11-11 17:01:15 -0500 |
|---|---|---|
| committer | Daniel <[email protected]> | 2024-11-11 17:01:15 -0500 |
| commit | a10ffb59d1901dccf73c560bf8d24936738050d7 (patch) | |
| tree | 0e830d5eae08e2138afefb831076bf682a15a501 /bin/.local | |
| parent | 30b9f940832ef0f64e4a36d8635b500f70093c01 (diff) | |
mega status script (all blocks)
Diffstat (limited to 'bin/.local')
| -rwxr-xr-x | bin/.local/bin/scripts/status/all | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/bin/.local/bin/scripts/status/all b/bin/.local/bin/scripts/status/all new file mode 100755 index 0000000..22ca92e --- /dev/null +++ b/bin/.local/bin/scripts/status/all @@ -0,0 +1,152 @@ +#!/bin/bash + +#### WEATHER +url="${WTTRURL:-wttr.in}" +weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" + +getforecast() { curl -sf "$url/Louisville?M" > "$weatherreport" || exit 1; } + +checkforecast() { + [ -s "$weatherreport" ] && [ "$(stat -c %y "$weatherreport" 2>/dev/null | + cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] +} + +getprecipchance() { + echo "$weatherdata" | sed '16q;d' | + grep -wo "[0-9]*%" | + sort -rn | + head -1q +} + +getdailyhighlow() { + echo "$weatherdata" | sed '13q;d' | + grep -o "m\\([-+]\\)*[0-9]\\+" | + sed 's/[+m]//g' | + sort -g | + sed -e 1b -e '$!d' +} + +readfile() { weatherdata="$(cat "$weatherreport")" ;} + +showweather() { + checkforecast || getforecast + readfile + printf "β%s π₯Ά%sΒ°C π%sΒ°C" "$(getprecipchance)" $(getdailyhighlow) +} + +#### CLOCK +clock=$(date '+%I') + +case "$clock" in + "00") clockicon="π" ;; + "01") clockicon="π" ;; + "02") clockicon="π" ;; + "03") clockicon="π" ;; + "04") clockicon="π" ;; + "05") clockicon="π" ;; + "06") clockicon="π" ;; + "07") clockicon="π" ;; + "08") clockicon="π" ;; + "09") clockicon="π" ;; + "10") clockicon="π" ;; + "11") clockicon="π" ;; + "12") clockicon="π" ;; +esac + +calendar_icon="π
" + +showclock () { + printf "%s" $(date "+$calendar_icon %Y-%m-%d (%a) $clockicon %R:%S") +} + +#### BATTERY +showbattery () { + for battery in /sys/class/power_supply/BAT?*; do + [ -n "${capacity+x}" ] && printf " " + case "$(cat "$battery/status" 2>&1)" in + "Full") status="β‘" ;; + "Discharging") status="π" ;; + "Charging") status="π" ;; + "Not charging") status="π" ;; + "Unknown") status="β»οΈ" ;; + *) exit 1 ;; + esac + capacity="$(cat "$battery/capacity" 2>&1)" + [ "$status" = "π" ] && [ "$capacity" -le 25 ] && warn="β" + printf "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn + done +} + +#### NETWORK +# Wifi +if [ "$(cat /sys/class/net/w*/operstate 2>/dev/null)" = 'up' ] ; then + wifiicon="$(awk '/^\s*w/ { print "πΆ", int($3 * 100 / 70) "% " }' /proc/net/wireless)" +elif [ "$(cat /sys/class/net/w*/operstate 2>/dev/null)" = 'down' ] ; then + [ "$(cat /sys/class/net/w*/flags 2>/dev/null)" = '0x1003' ] && wifiicon="π‘ " || wifiicon="β " +fi + +# Ethernet +[ "$(cat /sys/class/net/e*/operstate 2>/dev/null)" = 'up' ] && ethericon="π" || ethericon="β" + +# TUN +[ -n "$(cat /sys/class/net/tun*/operstate 2>/dev/null)" ] && tunicon=" π" + +shownetwork() { + printf "%s%s%s" "$wifiicon" "$ethericon" "$tunicon" +} + +#### MUSIC + +truncate() { + echo "$1" | cut -c1-15 +} + +# Get current track info +artist="$(playerctl metadata artist 2>/dev/null || echo "none")" +title="$(playerctl metadata title 2>/dev/null || echo "none")" + +# Truncate artist and title to 15 characters +truncated_artist=$(truncate "$artist") +truncated_title=$(truncate "$title") + +# Format the output as "artist - title" +current_track="$truncated_artist - $truncated_title" + +playerstatus=$(playerctl status) + +case "$playerstatus" in + "Playing") playericon="π΅" ;; + "Paused") playericon="βΈοΈ" ;; + "Stopped") playericon="βΉοΈ" ;; + "*") playericon="" ;; +esac + +# Print the current track +showmusic () { + echo "$playericon $current_track" +} + +#### MEMORY +showmemory () { + free --mebi | sed -n '2{p;q}' | awk '{printf ("π§ %2.2fGiB/%2.2fGiB\n", ( $3 / 1024), ($2 / 1024))}' +} + +#### VOLUME + +mutestatus="pactl list sinks | grep -q 'Mute: yes' && echo $?" + +case "$mutestatus" in + 0) + soundicon="π" ;; + *) + soundicon="π" ;; +esac + +showvolume() { + volumeInput=$(pactl list sinks) + currentVolume=$(echo "${volumeInput#*Sink #$sinkNumber}" | grep -E 'V.*-left' | grep -oE '[0-9]+%' | tail -n 1) + printf "%s %s" $soundicon $currentVolume +} + +#### CONCATENATION +echo -e $(showmemory) "|" $(showweather) "|" $(shownetwork) "|" $(showmusic) "|" $(showvolume) "|" $(showbattery) "|" $(showclock) |
