diff options
| author | Franck Cuny <franck@fcuny.net> | 2023-03-11 19:23:03 -0800 |
|---|---|---|
| committer | Franck Cuny <franck@fcuny.net> | 2023-03-11 19:23:03 -0800 |
| commit | 54ae461302f1d397f5d395f0ac1a237261ee2e4f (patch) | |
| tree | 9d4450ea40bdfa2177d45f5bda3bb9e78e9cf399 /home/wm/waybar/waybar-systemd.sh | |
| parent | home/shell: switch the default shell back to zsh (diff) | |
| download | infra-54ae461302f1d397f5d395f0ac1a237261ee2e4f.tar.gz | |
home/swaybar: add an indicator for systemd unit
Reports the number of systemd units (user and systems) that are in
failed state.
Diffstat (limited to '')
| -rwxr-xr-x | home/wm/waybar/waybar-systemd.sh | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/home/wm/waybar/waybar-systemd.sh b/home/wm/waybar/waybar-systemd.sh new file mode 100755 index 0000000..bf4e8b8 --- /dev/null +++ b/home/wm/waybar/waybar-systemd.sh @@ -0,0 +1,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 |
