z_mirror/dotfiles

git clone https://git.raiguard.me/z_mirror/dotfiles

Caleb HeuerFix sway status line81df58c

noctalia
3.0 KiB91 linesraw
1#!/bin/sh
2
3red="#f7768e"
4green="#9ece6a"
5yellow="#e0af68"
6orange="#ff9e64"
7blue="#7aa2f7"
8magenta="#bb9af7"
9cyan="#7dcfff"
10
11hwmon=$(find /sys/class/drm/card1/device/hwmon -type d -name hwmon[0-9])
12
13while true; do
14    # CPU info
15    cpuusage=$(mpstat 1 1 | awk '/M  all/ { printf "%.1f%%", 100 - $13 }')
16    cputemp=$(sensors | awk '
17      /Package/ { printf "%.0f°C\n", substr($4, 2, length($4) - 3) }
18      /Tdie/ { printf "%.0f°C\n", substr($2, 2, length($2) - 2) }
19    ' | head -1)
20    if [ -n "$cputemp" ]; then
21      cputemp="  $cputemp"
22    fi
23    cpu="<span foreground='$magenta'>$cpuusage$cputemp</span>  "
24
25    # RAM info
26    used=$(free | awk '/Mem/ { printf "%.2f \n", $3/1024/1024 }')
27    ram="<span foreground='$cyan'>${used}GB</span>  "
28
29    # Network
30    ssid=$(nmcli connection show --active | grep wifi | cut -f 1 -d " ")
31    if [ -n "$ssid" ]; then
32        network="<span foreground='$blue'>$ssid</span>  "
33    else
34        network=""
35    fi
36
37    # GPU
38    if [ "$HOSTNAME" = "tantal" ]; then
39        gpubusy=$(cat "/sys/class/drm/card1/device/gpu_busy_percent")
40        gputemp=$(cat "$hwmon/temp1_input")
41        gputemp=$(expr $gputemp / 1000)
42        gpu="<span foreground='$red'>$gpubusy%  $gputemp°C</span>  "
43    fi
44
45    # Do-not-disturb
46    if $(makoctl mode | grep -q "do-not-disturb"); then
47        dnd="<span foreground='$orange'>DND</span>  "
48    fi
49
50    # Battery info
51    if [ "$HOSTNAME" = "uraya" ]; then
52        # Pen tablet
53        tablet_path=$(upower -d | grep Device: | grep wacom_battery \
54            | awk '{ print $2 }')
55        if [ -n "$tablet_path" ]; then
56            tablet_info=$(upower -i "$tablet_path")
57            tablet_color=$green
58            tablet_charge=$(echo "$tablet_info" | grep percentage \
59                | awk '{ print $2 }' | sed "s/%//")
60            if [ "$tablet_charge" -lt 21 ]; then
61                tablet_color=$red
62            fi
63            tablet_status=$(echo "$tablet_info" | grep "power supply" \
64                | awk '/yes/ { print "+" }')
65            tablet_bat="<span foreground='$tablet_color'>T:$tablet_status$tablet_charge%</span>  "
66        else
67            tablet_bat=""
68        fi
69        # Laptop
70        bat_color=$green
71        bat_status=$(cat /sys/class/power_supply/BAT1/status \
72            | awk '/Charging/ { print "+" }')
73        bat_charge=$(cat /sys/class/power_supply/BAT1/capacity)
74        if [ "$bat_charge" -lt 21 ]; then
75            bat_color=$red
76        fi
77        # Wattage
78        bat_wattage=$(echo - | awk "{printf \"%.1f\", \
79          $(( \
80            $(cat /sys/class/power_supply/BAT1/current_now) * \
81            $(cat /sys/class/power_supply/BAT1/voltage_now) \
82          )) / 1000000000000 }")
83        bat="$tablet_bat<span foreground='$bat_color'>$bat_status$bat_charge%  $bat_wattage W</span>  "
84    fi
85    date=$(date +'%a %b %d')
86    if [ $(date +%Z) != "CEST" ]; then
87      prague="$(TZ=Europe/Prague date +'%-H:%M %Z') "
88    fi
89    local=$(date +"%-H:%M %Z")
90    echo "$cpu$ram$gpu$dnd$bat$network$date $prague$local"
91done