Krolyxon
Commit 61591c8

Branches

Refs →

aurora.localbinhyprlockinfo

45 lines · 2.3 KB · Bourne Again Shell (bash)

1#!/bin/sh
2# hyprlock's live labels in aurora's look (~/.config/hypr/hyprlock.conf); prints Pango markup.
3# Colours and settings come from aurora's Theme.qml (~/.config/aurora/hyprlock-colors.conf) as arguments.
4# lockinfo clock HOURFMT BLINK FONT HH:MM in FONT (a Pango font_desc); the colon dims every other half second if BLINK=1
5# lockinfo info weather from aurora's cache (if < 3h old) · what's playing
6# lockinfo battery LOW ERR FG battery glyph (FG, ERR at or below LOW% on battery) + percentage
7
8esc() { sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g'; }
9# aurora's Lb: Space Mono caps, tracking .14em (the label's font_size is 9pt = 12px)
10lb() { printf "<span letter_spacing='1290' text_transform='uppercase'>%s</span>" "$1"; }
11
12case "$1" in
13clock)
14 set -- $(date +"$2 %M %N") "$3" "$4"
15 colon=":"
16 [ "$4" = 1 ] && [ "${3%"${3#?}"}" -ge 5 ] && colon="<span alpha='20%'>:</span>"
17 printf "<span font_desc='%s'>%s%s%s</span>" "$5" "$1" "$colon" "$2"
18 ;;
19info)
20 f="$HOME/.cache/aurora/weather.json"
21 w=$([ -r "$f" ] && jq -r 'select(now * 1000 - .fetched < 3 * 3600 * 1000) | .raw.current | .weather_code as $c
22 | "\(.temperature_2m | round)° " + (if $c <= 1 then "clear" elif $c == 2 then "partly cloudy"
23 elif $c == 3 then "overcast" elif $c < 50 then "fog" elif $c < 60 then "drizzle" elif $c < 70 then "rain"
24 elif $c < 80 then "snow" elif $c < 83 then "showers" elif $c < 90 then "snow showers" else "thunder" end)' "$f" 2>/dev/null)
25 m=$(playerctl metadata --format '{{title}} {{artist}}' 2>/dev/null)
26 t=${m%% *} a=${m#* }
27 [ -n "$t" ] && m="$t${a:+ — $a}" || m=""
28 line=$(printf '%s\n%s\n' "$w" "$m" | sed '/^$/d' | esc | sed ':a;N;$!ba;s/\n/ · /')
29 [ -n "$line" ] && lb "$line"
30 ;;
31battery)
32 b=$(ls -d /sys/class/power_supply/BAT* 2>/dev/null | head -n 1)
33 [ -n "$b" ] || exit 0
34 p=$(cat "$b/capacity") s=$(cat "$b/status")
35 # glyphs = Theme.qml's batIcon: charging, on AC, else 10 levels (Theme.batLevels)
36 case "$s" in
37 Charging) g=F0084 ;;
38 Discharging) g=$(echo "F007A F007B F007C F007D F007E F007F F0080 F0081 F0082 F0079" | cut -d' ' -f$((p >= 100 ? 10 : p / 10 + 1))) ;;
39 *) g=F06A5 ;;
40 esac
41 colour=$4
42 [ "$s" = Discharging ] && [ "$p" -le "$2" ] && colour=$3
43 printf "<span font_desc='JetBrainsMono Nerd Font 12.75' foreground='%s'>&#x%s;</span> %s" "$colour" "$g" "$(lb "$p%")"
44 ;;
45esac