summaryrefslogtreecommitdiff
path: root/bin/statusbar
blob: a0b61d57e3c5c3b821ec64f6abe1f690411d05ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh -u

volume() {
	volume=$(pactl get-sink-volume @DEFAULT_SINK@ | sed -nE 's/.*\s([0-9]+)%.*/\1/p')
	if [ "$(pactl get-sink-mute @DEFAULT_SINK@)" = "Mute: yes" ]; then
		volume_symbol="󰝟"
	elif [ "$volume" -eq 0 ]; then
		volume_symbol=""
	elif [ "$volume" -le 50 ]; then
		volume_symbol=""
	else
		volume_symbol=""
	fi
	printf '<span foreground="#ed8796">%s %d%%</span>' "$volume_symbol" "$volume"
}

network() {
	ssid=$(iwgetid -r)
	if [ -n "$ssid" ]; then
		symbol="󰖩 "
	else
		symbol="󰖪"
	fi
	printf '<span foreground="#f5a97f">%s %s</span>' "$symbol" "$ssid"
}

brightness() {
	brightness=$(brightnessctl -m | awk -F, '{ print $4 }')
	printf '<span foreground="#eed49f"> %s</span>' "$brightness"
}

battery() {
	status=$(cat /sys/class/power_supply/BAT0/status)
	capacity=$(cat /sys/class/power_supply/BAT0/capacity)

	idx=$(((capacity - 1) / 10 + 1))
	case "$status" in
	"Discharging")
		symbol=$(echo '<span foreground="#ed8796">󰂃</span>,󰁻,󰁼,󰁽,󰁾,󰁿,󰂀,󰂁,󰂂,󰁹' |
			awk -F, "{ print \$$idx }")
		;;
	"Charging")
		symbol=$(echo "󰢜 󰂆 󰂇 󰂈 󰢝 󰂉 󰢞 󰂊 󰂋 󰂅" | awk "{ print \$$idx }")
		;;
	"Full")
		symbol="󰂄"
		;;
	esac
	printf '<span foreground="#a6da95">%s %d%%</span>' "$symbol" "$capacity"
}

clock() {
	printf '<span foreground="#7dc4e4"> %s</span>' "$(date '+%b %d %H:%M')"
}

while true; do
	somebar -c status "<span foreground=\"#cad3f5\">$(volume) | $(network) | $(brightness) | $(battery) | $(clock)</span>"
	sleep 0.2
done