1packages_total() {
2 total=$(pacman -Qe | wc -l)
3 updates=$(checkupdates | wc -l)
4 if [ "$updates" -gt 10 ]; then
5 text=" $total"
6 tooltip="Updates available"
7 else
8 text=" $total"
9 tooltip="Installed Packages: $total\nNo Updates available"
10 fi
11
12 printf '{"text":"%s","tooltip":"%s"}\n' "$text" "$tooltip"
13
14}
15
16show_pkg_info() {
17 local pkg="$1"
18 pacman -Qi "$pkg" 2>&1 | zenity --text-info \
19 --title="Package Info: $pkg" \
20 --font="monospace 10"
21}
22
23
24packages_installed_explicitly() {
25 out=$(pacman -Qi - < <(
26 pacman -Qiqe | awk -F': ' '/^Name/ {name=$2}/^Install Date/ {
27 cmd = "date -d \"" $2 "\" +\"%Y-%m-%d %H:%M:%S\""
28 cmd | getline iso
29 close(cmd)
30 print iso, name
31 }' | sort -r | awk '{print $NF}'
32 ) | awk -v RS= '
33 {
34 # Extract fields using Regex from the full text block
35 match($0, /Name[[:space:]]*:[[:space:]]*([^\n]*)/, n)
36 match($0, /Version[[:space:]]*:[[:space:]]*([^\n]*)/, v)
37 match($0, /Description[[:space:]]*:[[:space:]]*([^\n]*)/, d)
38
39 name = n[1]
40 ver = v[1]
41 desc = d[1]
42
43 # Truncate Description
44 if (length(desc) > 80) desc = substr(desc, 1, 80) "…"
45
46 # Escape Ampersands (Critical for Rofi Pango markup)
47 gsub("&", "&", desc)
48 gsub("<", "<", desc)
49 gsub(">", ">", desc)
50
51 # Output formatted string
52 printf "📦 <b>%s</b> (%s)\n<span size=\"small\">%s</span>\x0f", name, ver, desc
53 }
54 ')
55 selected_package_raw=$(printf "%b" "$out" | rofi -dmenu -sep $'\x0f' -eh 2 -i -p "Packages :" -no-show-icons -markup-rows -no-cycle -theme-str 'listview {lines:5;}')
56
57 if [[ -n "$selected_package_raw" ]]; then
58 pkg_name=$(echo "$selected_package_raw" | sed -E 's/.*<b>([^<]+)<\/b>.*/\1/' | head -n 1)
59
60 action=$(printf "Info\nUninstall\nCancel" | rofi -dmenu -i -theme $HOME/.wraith/theme/scripts.rofi.rasi -theme-str 'listview {lines:3;}')
61 case "$action" in
62 "Info")
63 show_pkg_info "$pkg_name"
64 ;;
65 "Uninstall")
66 smart-launch --tui "Uninstall Package $pkg_name" "bash -c 'sudo pacman -Rns $pkg_name --noconfirm; gum spin --spinner moon --title \"Press any key to close...\" -- bash -c \"read -n 1 -s\"'"
67 ;;
68 *)
69 exit 0
70 ;;
71 esac
72 fi
73
74}
75
76pkg_update(){
77
78 update_list=$(checkupdates 2>/dev/null)
79 updates=$(echo "$update_list" | wc -l)
80
81 if [ "$updates" -lt 10 ]; then
82 packages_installed_explicitly
83 exit 0
84 fi
85
86 zenity --question \
87 --title="System Updates Available" \
88 --width=600 --height=400 \
89 --ok-label="Update" \
90 --cancel-label="Ignore" \
91 --text="The following $updates updates are available:
92
93$update_list
94
95Do you want to update now?"
96
97 if [ $? -eq 0 ]; then
98 (
99 pkexec pacman -Syu --noconfirm 2>&1 | while read -r line; do
100 echo "# $line"
101 echo "50"
102 done
103 echo "100"
104 ) | zenity --progress \
105 --title="Updating System" \
106 --text="Starting update..." \
107 --percentage=0 \
108 --auto-close
109 fi
110
111}
112
113
114case "$1" in
115 "details")
116 packages_total
117 ;;
118 "update")
119 pkg_update
120 ;;
121 "")
122 packages_installed_explicitly
123 ;;
124 *)
125 echo "Error: Unknown command: $1" >&2
126 exit 1
127 ;;
128esac