Unix3r

Build. Break. Learn. Repeat.

Starting0%
Skip to content

unix3r/dotfiles

Public
main
U Unix3r Initial commit: sway + waybar dotfiles (Catppuccin Mocha) eb290df
34 lines · 1.2 KB Raw History
1#!/usr/bin/env bash
2# updates.sh — count pending package updates (apt / pacman / dnf).
3# updates.sh → JSON for waybar
4# updates.sh --upgrade → run the upgrade in a terminal, then refresh waybar
5has() { command -v "$1" >/dev/null 2>&1; }
6
7if [[ $1 == --upgrade ]]; then
8 if has apt; then sudo apt update && sudo apt upgrade
9 elif has pacman; then sudo pacman -Syu
10 elif has dnf; then sudo dnf upgrade
11 fi
12 has flatpak && flatpak update
13 pkill -RTMIN+10 waybar
14 read -rp "Done — press Enter to close"
15 exit
16fi
17
18count=0; list=""
19if has apt; then
20 list=$(apt list --upgradable 2>/dev/null | tail -n +2 | cut -d/ -f1)
21elif has checkupdates; then
22 list=$(checkupdates 2>/dev/null | awk '{print $1}')
23elif has dnf; then
24 list=$(dnf -q check-update 2>/dev/null | awk 'NF==3{print $1}')
25fi
26[[ -n $list ]] && count=$(wc -l <<<"$list")
27
28if (( count > 0 )); then
29 tip=$(head -n 20 <<<"$list" | sed ':a;N;$!ba;s/\n/\\n/g')
30 (( count > 20 )) && tip+="\\n… and $((count-20)) more"
31 printf '{"text":" %s","class":"pending","tooltip":"%s updates:\\n%s\\n\\nclick to upgrade"}\n' "$count" "$count" "$tip"
32else
33 printf '{"text":"","class":"none","tooltip":"System is up to date"}\n'
34fi