summaryrefslogtreecommitdiff
path: root/ar/.local/bin/dmenuupgrade
blob: b43ff4c8a96b915ba4cc34296e91e7d586a845dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/sh

# Get list of pacman and yay upgradable packages
pacman_updates=$(pacman -Qu)
yay_updates=$(yay -Qu)

# Count the number of upgradable packages, filtering yay's output to count only AUR packages
pacman_count=$(printf "%s" "$pacman_updates" | grep -c '^\S')
aur_count=$(printf "%s" "$yay_updates" | grep -c '^\[AUR\]')

# Display the upgrade options with package counts
selection=$(printf "All\nPacman(%d)\nAUR(%d)" "$pacman_count" "$aur_count" | dmenu -i -p "Upgrade Option:")

case "$selection" in
"All")
  if [ "$(printf "No\nYes" | dmenu -i -p 'Proceed with upgrade for all packages?')" = "Yes" ]; then
    notify-send "📦 Upgrading all packages..."
    yay -Syu --noconfirm
    pkill -RTMIN+16 "${STATUSBAR:-dwmblocks}"
    notify-send "✅ Upgrade of all packages completed."
  else
    notify-send "❌ Upgrade cancelled."
    exit 0
  fi
  ;;
"Pacman($pacman_count)")
  # Show all upgradable pacman packages with "Upgrade All" option
  selection=$(printf "Upgrade All\n%s" "$pacman_updates" | dmenu -i -l 10 -p "Pacman: Upgrade or Open URL:")
  case "$selection" in
  "Upgrade All")
    if [ "$(printf "No\nYes" | dmenu -i -p 'Proceed with pacman upgrade?')" = "Yes" ]; then
      notify-send "📦 Upgrading pacman packages..."
      printf "%s" "$pacman_updates" | awk '{print $1}' | xargs sudo pacman -S --noconfirm
      pkill -RTMIN+16 "${STATUSBAR:-dwmblocks}"
      notify-send "✅ Pacman packages upgrade completed."
    else
      notify-send "❌ Upgrade cancelled."
      exit 0
    fi
    ;;
  *)
    # Individual package selected: Prompt to upgrade or open URL
    action=$(printf "Upgrade\nOpen URL" | dmenu -i -p "Package: $selection")
    case "$action" in
    "Upgrade")
      if [ "$(printf "No\nYes" | dmenu -i -p 'Proceed with upgrade for this package?')" = "Yes" ]; then
        notify-send "📦 Upgrading package: $selection..."
        sudo pacman -S --noconfirm "$(printf "%s" "$selection" | awk '{print $1}')"
        pkill -RTMIN+16 "${STATUSBAR:-dwmblocks}"
        notify-send "✅ Upgrade completed for package: $selection."
      else
        notify-send "❌ Upgrade cancelled."
        exit 0
      fi
      ;;
    "Open URL")
      if [ "$(printf "No\nYes" | dmenu -i -p 'Open URL?')" = "Yes" ]; then
        xdg-open "https://archlinux.org/packages/?q=$(printf "%s" "$selection" | awk '{print $1}')" >/dev/null 2>&1 &
      else
        exit
      fi
      ;;
    esac
    ;;
  esac
  ;;
"AUR($aur_count)")
  # Show all upgradable AUR packages with "Upgrade All" option
  aur_updates=$(printf "%s" "$yay_updates" | grep '^\[AUR\]')
  selection=$(printf "Upgrade All\n%s" "$aur_updates" | dmenu -i -l 10 -p "AUR: Upgrade or Open URL:")
  case "$selection" in
  "Upgrade All")
    if [ "$(printf "No\nYes" | dmenu -i -p 'Proceed with AUR upgrade?')" = "Yes" ]; then
      notify-send "📦 Upgrading AUR packages..."
      yay -Syu --aur --noconfirm
      pkill -RTMIN+16 "${STATUSBAR:-dwmblocks}"
      notify-send "✅ AUR packages upgrade completed."
    else
      notify-send "❌ Upgrade cancelled."
      exit 0
    fi
    ;;
  *)
    # Individual AUR package selected: Prompt to upgrade or open URL
    action=$(printf "Upgrade\nOpen URL" | dmenu -i -p "Package: $selection")
    case "$action" in
    "Upgrade")
      if [ "$(printf "No\nYes" | dmenu -i -p 'Proceed with upgrade for this package?')" = "Yes" ]; then
        notify-send "📦 Upgrading AUR package: $selection..."
        yay -S --noconfirm "$(printf "%s" "$selection" | awk '{print $2}')"
        pkill -RTMIN+16 "${STATUSBAR:-dwmblocks}"
        notify-send "✅ Upgrade completed for AUR package: $selection."
      else
        notify-send "❌ Upgrade cancelled."
        exit 0
      fi
      ;;
    "Open URL")
      if [ "$(printf "No\nYes" | dmenu -i -p 'Open URL?')" = "Yes" ]; then
        xdg-open "https://aur.archlinux.org/packages/?O=0&K=$(printf "%s" "$selection" | awk '{print $2}')" >/dev/null 2>&1 &
      else
        exit
      fi
      ;;
    esac
    ;;
  esac
  ;;
*)
  notify-send "❌ Invalid selection."
  exit 0
  ;;
esac

remaps