Redesign Eww bars
This commit is contained in:
61
modules/home/wayland/apps/eww/bar/scripts/sys/battery
Executable file
61
modules/home/wayland/apps/eww/bar/scripts/sys/battery
Executable file
@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
icons=("" "" "" "" "" "" "" "" "" "" "")
|
||||
num_icons=$(awk -v n="${#icons[@]}" 'BEGIN{print 100 / n}')
|
||||
BATTERY="/sys/class/power_supply/BAT0"
|
||||
|
||||
geticon() {
|
||||
level=$(awk -v n="$CAPACITY" -v c="$num_icons" 'BEGIN{print int(n/c-1)}')
|
||||
echo "${icons[$level]}"
|
||||
}
|
||||
|
||||
status() {
|
||||
if [ "$STATE" = "Charging" ]; then
|
||||
echo -n "charging"
|
||||
|
||||
if [ "$RATE" -gt 0 ]; then
|
||||
echo ", $(gettime) left"
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
elif [ "$STATE" = "Discharging" ]; then
|
||||
echo "$(gettime)h left"
|
||||
else
|
||||
echo "fully charged"
|
||||
fi
|
||||
}
|
||||
|
||||
color() {
|
||||
[ "$CAPACITY" -le 20 ] && echo '#f38ba8' || echo '#a6e3a1'
|
||||
}
|
||||
|
||||
wattage() {
|
||||
awk -v rate="$RATE" -v uw="1000000" 'BEGIN{print sprintf("%.1f W", rate/uw)}'
|
||||
}
|
||||
|
||||
gettime() {
|
||||
FULL=$(cat $BATTERY/energy_full)
|
||||
NOW=$(cat $BATTERY/energy_now)
|
||||
|
||||
if [ "$RATE" -gt 0 ]; then
|
||||
if [ "$STATE" = "Discharging" ]; then
|
||||
EX="$NOW / $RATE"
|
||||
else
|
||||
EX="($FULL - $NOW) / $RATE"
|
||||
fi
|
||||
date -u -d@"$(awk -v ex="$EX" 'BEGIN{print ex * 3600}')" +%H:%M
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -d "$BATTERY" ]; then
|
||||
while true; do
|
||||
RATE=$(cat $BATTERY/power_now)
|
||||
CAPACITY=$(cat $BATTERY/capacity)
|
||||
STATE=$(cat $BATTERY/status)
|
||||
|
||||
echo '{ "visible": true, "icon": "'$(geticon)'", "percentage": '$CAPACITY', "wattage": "'$(wattage)'", "status": "'$(status)'", "color": "'$(color)'" }'
|
||||
sleep 15
|
||||
done
|
||||
else
|
||||
echo '{ "visible": false, "icon": "", "percentage": 0, "wattage": "", "status": "", "color": "#a6e3a1" }'
|
||||
fi
|
1
modules/home/wayland/apps/eww/bar/scripts/sys/cpu
Executable file
1
modules/home/wayland/apps/eww/bar/scripts/sys/cpu
Executable file
@ -0,0 +1 @@
|
||||
#!/usr/bin/env bash
|
3
modules/home/wayland/apps/eww/bar/scripts/sys/gpu
Executable file
3
modules/home/wayland/apps/eww/bar/scripts/sys/gpu
Executable file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
amdgpu_top -J -s 5000 | sed 's/ //g'
|
14
modules/home/wayland/apps/eww/bar/scripts/sys/memory
Executable file
14
modules/home/wayland/apps/eww/bar/scripts/sys/memory
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
total="$(free --si | rg Mem | awk '{print $2}')"
|
||||
|
||||
human() {
|
||||
awk -v mem="$1" 'BEGIN{print sprintf("%.1f%s", mem/1000/(mem > 1000000 ? 1000 : 1), mem > 1000000 ? "G" : "M")}'
|
||||
}
|
||||
|
||||
free --si -s 3 | rg --line-buffered Mem | while read -r line; do
|
||||
used=$(echo "$line" | awk '{print $3}')
|
||||
perc=$(awk -v used="$used" -v total="$total" 'BEGIN{print sprintf("%.f", used/total*100)}')
|
||||
|
||||
echo '{"total": "'$(human "$total")'", "used": "'$(human "$used")'", "percent": '$perc'}'
|
||||
done
|
Reference in New Issue
Block a user