waybar changes 1

This commit is contained in:
cnst
2024-12-27 16:46:50 +01:00
parent 542bac2fe7
commit 10716da678
22 changed files with 1007 additions and 159 deletions

52
scripts/bin/waybar-systemd.sh Executable file
View File

@@ -0,0 +1,52 @@
# This is a modified version of a script from @maximbaz
SYSTEMCTL="/run/current-system/sw/bin/systemctl"
WC="/run/current-system/sw/bin/wc"
failed_user_output=$("$SYSTEMCTL" --plain --no-legend --user list-units --state=failed --type=service 2>/dev/null)
failed_system_output=$("$SYSTEMCTL" --plain --no-legend list-units --state=failed --type=service)
if [[ -z "$failed_system_output" ]]; then
failed_systemd_count=0
else
failed_systemd_count=$("$WC" -l <<<"$failed_system_output")
fi
if [[ -z "$failed_user_output" ]]; then
failed_user_count=0
else
failed_user_count=$("$WC" -l <<<"$failed_user_output")
fi
total_failed=$((failed_systemd_count + failed_user_count))
if [[ "$total_failed" -eq 0 ]]; then
printf '{"text": ""}\n'
else
tooltip=""
if [[ -n "$failed_system_output" ]]; then
failed_system=$(echo "$failed_system_output" | /run/current-system/sw/bin/awk '{print $1}')
tooltip+="Failed system services: "
if [[ "$failed_systemd_count" -gt 1 ]]; then
failed_system_indented="${failed_system//$'\n'/\\n }"
tooltip+="$failed_system_indented"
else
tooltip+="$failed_system"
fi
fi
if [[ -n "$failed_user_output" ]]; then
failed_user=$(echo "$failed_user_output" | /run/current-system/sw/bin/awk '{print $1}')
if [[ -n "$tooltip" ]]; then tooltip+="\n"; fi
tooltip+="Failed user services: "
if [[ "$failed_user_count" -gt 1 ]]; then
failed_user_indented="${failed_user//$'\n'/\\n }"
tooltip+="$failed_user_indented"
else
tooltip+="$failed_user"
fi
fi
escaped_tooltip="${tooltip//$'\\n'/\\\\n}"
printf '{"text": " %d", "tooltip": "%s"}\n' "$total_failed" "$escaped_tooltip"
fi