pkg-remove (2068B)
1 #!/usr/bin/env bash 2 3 set -euo pipefail 4 5 # Colors 6 RED='\e[31m' 7 GREEN='\e[32m' 8 YELLOW='\e[33m' 9 BLUE='\e[34m' 10 BOLD='\e[1m' 11 RESET='\e[0m' 12 13 # Check required tools 14 for tool in fzf pacman; do 15 if ! command -v "$tool" >/dev/null 2>&1; then 16 echo -e "${RED}Error: $tool is not installed${RESET}" 17 notify-send "ERROR" "$tool is not installed." 18 exit 1 19 fi 20 done 21 22 # FZF configuration 23 fzf_args=( 24 --multi 25 --preview 'pacman -Qi {1}' 26 --preview-label-pos='bottom' 27 --preview-window 'down:65%:wrap' 28 --color 'pointer:red,marker:red' 29 --header='Select packages to REMOVE (TAB to select multiple, ENTER to confirm)' 30 --border 31 ) 32 33 echo -e "${BLUE}${BOLD}Loading installed packages...${RESET}\n" 34 35 # Get package selections (use pacman instead of yay for compatibility) 36 if command -v yay >/dev/null 2>&1; then 37 pkg_names=$(yay -Qqe | fzf "${fzf_args[@]}" || true) 38 else 39 pkg_names=$(pacman -Qqe | fzf "${fzf_args[@]}" || true) 40 fi 41 42 # Check if user selected anything 43 if [[ -z "$pkg_names" ]]; then 44 echo -e "${YELLOW}No packages selected. Exiting.${RESET}" 45 exit 0 46 fi 47 48 # Show what will be removed 49 echo -e "${RED}${BOLD} WARNING: The following packages will be REMOVED:${RESET}" 50 echo "$pkg_names" | sed 's/^/ - /' 51 echo 52 53 # Convert to array for safe handling 54 mapfile -t packages < <(echo "$pkg_names") 55 56 # Remove packages 57 echo -e "${RED}${BOLD}Removing ${#packages[@]} package(s)...${RESET}\n" 58 59 if sudo pacman -Rns --noconfirm "${packages[@]}"; then 60 echo 61 echo -e "${GREEN}${BOLD}✓ Successfully removed ${#packages[@]} package(s)${RESET}" 62 63 # Check for new orphans 64 orphans=$(pacman -Qtdq 2>/dev/null || true) 65 if [[ -n "$orphans" ]]; then 66 echo -e "${YELLOW}ℹ Found new orphaned packages (run pkg-update to clean them)${RESET}" 67 fi 68 else 69 echo 70 echo -e "${RED}${BOLD}✗ Removal failed or was incomplete${RESET}" 71 fi 72 73 echo 74 75 # Keep window open 76 if command -v gum >/dev/null 2>&1; then 77 gum spin --spinner "globe" --title "Done! Press any key to close..." -- bash -c 'read -n 1 -s' 78 else 79 echo -e "${BLUE}Press any key to close...${RESET}" 80 read -n 1 -s 81 fi