about summary refs log tree commit diff
path: root/home/wm/waybar/waybar-systemd.sh
blob: bf4e8b8dce7bb11ad30e8be5f21707aa79fd0867 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env bash

failed_user="$(systemctl --plain --no-legend --user list-units --state=failed | awk '{ print $1 }')"
failed_system="$(systemctl --plain --no-legend list-units --state=failed | awk '{ print $1 }')"

failed_systemd_count="$(echo -n "$failed_system" | grep -c '^')"
failed_user_count="$(echo -n "$failed_user" | grep -c '^')"

text=$(( failed_systemd_count + failed_user_count ))

if [ "$text" -eq 0 ]; then
    printf '{"text": ""}\n'
else
    tooltip=""

    [ -n "$failed_system" ] && tooltip="Failed system services:\n\n${failed_system}\n\n${tooltip}"
    [ -n "$failed_user" ]   && tooltip="Failed user services:\n\n${failed_user}\n\n${tooltip}"

    tooltip="$(printf  "%s" "$tooltip" | perl -pe 's/\n/\\n/g' | perl -pe 's/(?:\\n)+$//')"

    printf '{"text": "%s", "tooltip": "%s" }\n' "$text" "$tooltip"
fi