Eww update

This commit is contained in:
soraefir
2026-06-12 23:09:31 +02:00
parent 6140123cbc
commit 535c8a3154
15 changed files with 606 additions and 294 deletions

View File

@@ -0,0 +1,27 @@
#!/usr/bin/env bash
emit() {
local powered=false connected=false device=""
if bluetoothctl show 2>/dev/null | grep -q "Powered: yes"; then
powered=true
while IFS= read -r line; do
mac=$(echo "$line" | awk '{ print $2 }')
info=$(bluetoothctl info "$mac" 2>/dev/null)
if echo "$info" | grep -q "Connected: yes"; then
device=$(echo "$info" | awk -F': ' '/^\tName:/ { print $2; exit }')
connected=true
break
fi
done < <(bluetoothctl devices 2>/dev/null)
fi
printf '{"powered":%s,"connected":%s,"device":"%s"}\n' "$powered" "$connected" "$device"
}
emit
bluetoothctl monitor 2>/dev/null | while IFS= read -r line; do
case "$line" in
*"Powered"*|*"Connected"*|*"Device"*) emit ;;
esac
done

View File

@@ -1,81 +1,47 @@
#!/usr/bin/env zsh
#!/usr/bin/env bash
function get_time_ms {
date -u +%s%3N
}
icons=("󰤯" "󰤟" "󰤢" "󰤥" "󰤨")
function get_wifi_interface() {
get_wifi_iface() {
awk 'NR > 2 { gsub(":", "", $1); print $1; exit }' /proc/net/wireless
}
function toggle() {
status=$(rfkill | grep wlan | awk '{print $4}')
if [ "$status" = "unblocked" ]; then
rfkill block wlan
else
rfkill unblock wlan
fi
signal_icon() {
local dbm="$1"
if [ -z "$dbm" ]; then echo "󰤮"; return; fi
if [ "$dbm" -ge -50 ]; then echo "󰤨"
elif [ "$dbm" -ge -60 ]; then echo "󰤥"
elif [ "$dbm" -ge -70 ]; then echo "󰤢"
elif [ "$dbm" -ge -80 ]; then echo "󰤟"
else echo "󰤯"; fi
}
function gen_wifi() {
wifi_iface=$(get_wifi_interface)
signal=$(awk -v iface="$wifi_iface" '$1 == iface ":" { print $3; exit }' /proc/net/wireless)
level=$(awk -v n="$signal" 'BEGIN{print int((n-1)/20)}')
if [ "$level" -gt 4 ]; then
level=4
make_content() {
local wifi_iface eth_iface
wifi_iface=$(get_wifi_iface)
eth_iface=$(ip link | awk '/^[0-9]+: en[po]/ { gsub(":",""); print $2; exit }')
# Ethernet
local eth_connected=false
if [ -n "$eth_iface" ]; then
eth_state=$(ip link show "$eth_iface" 2>/dev/null | awk '/state/ { print $9 }')
[ "$eth_state" = "UP" ] && eth_connected=true
fi
icon=${icons[$level]}
ip="-"
class="net-connected"
name_raw=$(wpa_cli -g "/run/wpa_supplicant/$wifi_iface" status | grep \^ssid= | sed 's/ssid=//g')
name=$(printf "%s" "$name_raw")
}
function gen_ethernet() {
icon="󰈀"
class="net-connected"
ip=""
name=Wired
}
function make_content() {
local ethernet wifi wifi_iface
ethernet=$(ip link | rg "^[0-9]+: en[po]+" | head -n1 | sed 's/[a-zA-Z0-9_,><:\ -]*state //g' | sed 's/ mode [a-zA-Z0-9 ]*//g')
wifi_iface=$(get_wifi_interface)
if [ -n "$wifi_iface" ]; then
wifi=$(wpa_cli -g "/run/wpa_supplicant/$wifi_iface" status | rg "^wpa_state=" | sed 's/wpa_state=//g')
# WiFi — use IP presence as connection indicator (more reliable than wpa_cli)
local wifi_connected=false wifi_icon="󰤮" wifi_ssid=""
if [ -n "$wifi_iface" ] && ip -4 addr show "$wifi_iface" 2>/dev/null | grep -q "inet "; then
wifi_connected=true
wifi_ssid=$(wpa_cli -g "/run/wpa_supplicant/$wifi_iface" status 2>/dev/null \
| awk -F= '/^ssid=/ { print $2 }')
signal=$(awk -v iface="$wifi_iface" '$1 == iface ":" { gsub(/\./, "", $4); print $4; exit }' /proc/net/wireless)
wifi_icon=$(signal_icon "$signal")
fi
# test ethernet first
if [[ $ethernet == "UP" ]]; then
gen_ethernet
elif [[ $wifi == "COMPLETED" ]]; then
gen_wifi
else
icon="󰤮"
ip="-"
class="net-disconnected"
name="Disconnected"
fi
echo '{"icon": "'$icon'", "name": "'$name'", "ip": "'$ip'", "class": "'$class'"}'
printf '{"wifi":{"connected":%s,"icon":"%s","ssid":"%s"},"ethernet":{"connected":%s}}\n' \
"$wifi_connected" "$wifi_icon" "$wifi_ssid" "$eth_connected"
}
if [ "$1" = "toggle" ]; then
toggle
else
last_time=$(get_time_ms)
make_content
ip monitor | while read -r _; do
make_content
ip monitor | while read -r _; do
current_time=$(get_time_ms)
delta=$((current_time - last_time))
if [[ $delta -gt 50 ]]; then
make_content
last_time=$(get_time_ms)
fi
done
fi
done

View File

@@ -0,0 +1,49 @@
#!/usr/bin/env bash
COLS=4
declare -A prev_idle prev_total
emit_grid() {
local rows=() row_items=()
while IFS= read -r line; do
[[ $line =~ ^cpu([0-9]+) ]] || continue
local core="${BASH_REMATCH[1]}"
read -ra f <<< "$line"
local idle=$(( f[4] + f[5] ))
local total=0
for x in "${f[@]:1}"; do (( total += x )); done
local usage="0.0"
if [[ -n "${prev_total[$core]+x}" ]]; then
local dt=$(( total - prev_total[$core] ))
local di=$(( idle - prev_idle[$core] ))
(( dt > 0 )) && usage=$(awk "BEGIN{printf \"%.1f\", 100*(1-$di/$dt)}")
fi
prev_idle[$core]=$idle
prev_total[$core]=$total
local freq=0
local fpath="/sys/devices/system/cpu/cpu${core}/cpufreq/scaling_cur_freq"
[[ -r $fpath ]] && freq=$(( $(< "$fpath") / 1000 ))
row_items+=("{\"core\":$core,\"usage\":$usage,\"freq\":$freq}")
if (( ${#row_items[@]} == COLS )); then
local row; printf -v row '%s,' "${row_items[@]}"; row="${row%,}"
rows+=("[$row]")
row_items=()
fi
done < /proc/stat
if (( ${#row_items[@]} > 0 )); then
local row; printf -v row '%s,' "${row_items[@]}"; row="${row%,}"
rows+=("[$row]")
fi
local out; printf -v out '%s,' "${rows[@]}"; out="${out%,}"
echo "[$out]"
}
while true; do
emit_grid
sleep 2
done

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
dir=$(grep -rl k10temp /sys/class/hwmon/*/name 2>/dev/null | head -1 | xargs dirname)
awk '{printf "%.0f\n", $1/1000}' "$dir/temp1_input"

View File

@@ -1,3 +1,22 @@
#!/usr/bin/env zsh
amdgpu_top -J -s 5000 | sed 's/ //g'
#!/usr/bin/env bash
amdgpu_top -J -s 5000 | jq -c --unbuffered '.devices[0] | {
gfx_pct: (.gpu_activity.GFX.value // 0),
mem_pct: (.gpu_activity.Memory.value // 0),
media_pct: (.gpu_activity.MediaEngine.value // 0),
sclk: (.Sensors.GFX_SCLK.value // 0),
mclk: (.Sensors.GFX_MCLK.value // 0),
sclk_pct: (if (.Info["GPU Clock"].max != .Info["GPU Clock"].min) then
100 * ((.Sensors.GFX_SCLK.value // 0) - .Info["GPU Clock"].min) / (.Info["GPU Clock"].max - .Info["GPU Clock"].min)
else 0 end),
mclk_pct: (if (.Info["Memory Clock"].max != .Info["Memory Clock"].min) then
100 * ((.Sensors.GFX_MCLK.value // 0) - .Info["Memory Clock"].min) / (.Info["Memory Clock"].max - .Info["Memory Clock"].min)
else 0 end),
vclk: (.gpu_metrics.average_vclk_frequency // 0),
vclk_pct: (if (.Info["GPU Clock"].max > 0) then
100 * (.gpu_metrics.average_vclk_frequency // 0) / .Info["GPU Clock"].max
else 0 end),
temp: (.Sensors["Edge Temperature"].value // 0),
power: (.Sensors["Average Power"].value // 0),
vram_used: (.VRAM["Total VRAM Usage"].value // 0),
vram_total: (.VRAM["Total VRAM"].value // 1)
}'

View File

@@ -8,5 +8,6 @@ human() {
free --si -s 3 | rg --line-buffered Mem | while read -r line; do
used=$(echo "$line" | awk '{print $3}')
echo '{"human": { "total": "'$(human "$total")'", "used": "'$(human "$used")'"}, "total": "'$total'" , "used": "'$used'"}'
done
cached=$(echo "$line" | awk '{print $6}')
echo '{"human": {"total": "'$(human "$total")'", "used": "'$(human "$used")'", "cached": "'$(human "$cached")'"}, "total": "'$total'", "used": "'$used'", "cached": "'$cached'"}'
done

View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
free --si | awk '/Swap/ {
used=$3; total=$2
u = sprintf("%.1fG", used/1000000)
t = sprintf("%.1fG", total/1000000)
printf "{\"used\":%d,\"total\":%d,\"human\":{\"used\":\"%s\",\"total\":\"%s\"}}\n", used, total, u, t
}'